Rust learning: lessons, notes, and exercise crates
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
fn main() {
|
||||
let number = 3;
|
||||
|
||||
if number < 5 {
|
||||
println!("condition was true");
|
||||
} else {
|
||||
println!("condition was false");
|
||||
}
|
||||
|
||||
let number = 12;
|
||||
|
||||
if number % 4 == 0 {
|
||||
println!("number is divisible by 4");
|
||||
} else if number % 3 == 0 {
|
||||
println!("number is divisible by 3");
|
||||
} else if number % 2 == 0 {
|
||||
println!("number is divisible by 2");
|
||||
} else {
|
||||
println!("number is not divisible by 4, 3, or 2");
|
||||
}
|
||||
|
||||
let condition = true;
|
||||
let number = if condition { 5 } else { 6 };
|
||||
|
||||
println!("The value of number is: {number}");
|
||||
|
||||
{
|
||||
let x = 5;
|
||||
println!("this is five {x}")
|
||||
}
|
||||
|
||||
let mut count = 0;
|
||||
'counting_up: loop {
|
||||
println!("count = {count}");
|
||||
let mut remaining = 10;
|
||||
|
||||
loop {
|
||||
println!("remaining = {remaining}");
|
||||
if remaining == 9 {
|
||||
break;
|
||||
}
|
||||
if count == 2 {
|
||||
break 'counting_up;
|
||||
}
|
||||
remaining -= 1;
|
||||
}
|
||||
|
||||
count += 1;
|
||||
}
|
||||
println!("End count = {count}");
|
||||
|
||||
let a = [10, 20, 30, 40, 50];
|
||||
|
||||
for element in a {
|
||||
println!("the value is: {element}");
|
||||
}
|
||||
|
||||
for number in (1..4).rev() {
|
||||
println!("{number}!");
|
||||
}
|
||||
println!("LIFTOFF!!!");
|
||||
}
|
||||
Reference in New Issue
Block a user