Skip to content

Instantly share code, notes, and snippets.

@grahamking
Last active December 16, 2015 17:10
Show Gist options
  • Save grahamking/5468729 to your computer and use it in GitHub Desktop.
Save grahamking/5468729 to your computer and use it in GitHub Desktop.
Rust: Loop three ways
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