Created
June 18, 2022 12:38
-
-
Save SwannHERRERA/816eff5674332b61dbbb89b7c5eda3b3 to your computer and use it in GitHub Desktop.
rust do while loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! do_loop {( | |
$body:block while $cond:expr | |
) => ({ | |
let mut first = true; | |
while ::core::mem::replace(&mut first, false) || $cond | |
$body | |
})} | |
let mut x = 6; | |
do_loop!({ | |
if x == 6 { | |
x = 0; | |
continue; | |
} | |
x += 1; | |
println!("{}", x); | |
} while x < 6); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment