mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-03 15:40:17 +00:00
37 lines
632 B
Plaintext
37 lines
632 B
Plaintext
// `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!");
|
|
}
|