mirror of
https://github.com/ArthurDanjou/hellorust.git
synced 2026-01-14 20:19:28 +01:00
Learn Control Flow
This commit is contained in:
28
src/controlflow.rs
Normal file
28
src/controlflow.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
fn main() {
|
||||
conditional_assign();
|
||||
loops();
|
||||
}
|
||||
|
||||
fn conditional_assign() {
|
||||
let condition = true;
|
||||
let number = if condition { 5 } else { 6 };
|
||||
println!("The value of number is: {}", number);
|
||||
}
|
||||
|
||||
fn loops() {
|
||||
let mut number = 4;
|
||||
while number != 0 {
|
||||
println!("{}!", number);
|
||||
number -= 1;
|
||||
}
|
||||
|
||||
let a = [10, 20, 30, 40, 50];
|
||||
for element in a {
|
||||
println!("the value is: {}", element);
|
||||
}
|
||||
|
||||
for numbers in (1..4).rev() {
|
||||
println!("{} !", numbers);
|
||||
}
|
||||
println!("DÉCOLLAGE !!!");
|
||||
}
|
||||
Reference in New Issue
Block a user