2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-09 07:10:36 +00:00
cheat.sheets/sheets/rust/ControlFlow

37 lines
632 B
Plaintext
Raw Normal View History

2017-05-08 20:27:00 +00:00
// `for` loops/iteration
let array = [1, 2, 3];
for i in array.iter() {
println!("{}", i);
}
// Ranges
for i in 0u32..10 {
print!("{} ", i);
}
println!("");
// prints `0 1 2 3 4 5 6 7 8 9 `
// `if`
if 1 == 1 {
println!("Maths is working!");
} else {
println!("Oh no...");
}
// `if` as expression
let value = if true {
"good"
} else {
"bad"
};
// `while` loop
while 1 == 1 {
println!("The universe is operating normally.");
}
// Infinite loop
loop {
println!("Hello!");
}