Skip to content

Instantly share code, notes, and snippets.

@SwannHERRERA
Created June 18, 2022 12:38
Show Gist options
  • Save SwannHERRERA/816eff5674332b61dbbb89b7c5eda3b3 to your computer and use it in GitHub Desktop.
Save SwannHERRERA/816eff5674332b61dbbb89b7c5eda3b3 to your computer and use it in GitHub Desktop.
rust do while loop
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