Last active
December 16, 2015 17:10
-
-
Save grahamking/5468729 to your computer and use it in GitHub Desktop.
Rust: Loop three ways
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
fn main() { | |
for 2.times { | |
println("Basic loop sugar") | |
} | |
2.times(||{ println("Basic loop closure"); true }); | |
for [1,2,3].each |var| { | |
println(fmt!("Sugary loop %d", *var)); | |
} | |
[1,2,3].each(|var|{ | |
println(fmt!("Closurey loop %d", *var)); | |
true | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment