Created
July 15, 2014 20:45
-
-
Save tommie/71408da282761c237aa9 to your computer and use it in GitHub Desktop.
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
#![feature(macro_rules)] | |
macro_rules! cfor( | |
($($ident:ident = $pre:expr),*; $cond:expr; $($post:expr),*; $block:block) => ({ | |
$( let mut $ident = $pre; )* | |
while $cond { | |
$block | |
$( $post; )* | |
} | |
}); | |
) | |
fn main() { | |
cfor!(i = 0i, j = 1i; i < 5; i += 1, j += 2; { | |
println!("Hello {} {}", i, j); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank for your c loop in rust, it is very useful for me. To declare multiple mutable variables at the same time. Defined a macro to declare mutable variables as the following.