Compare commits
2 Commits
cfc4436eeb
...
7b9aad5fc8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b9aad5fc8 | ||
|
|
de13a80f99 |
@@ -42,4 +42,48 @@ fn main() {
|
|||||||
};
|
};
|
||||||
println!("New number for num2: {}",num2);
|
println!("New number for num2: {}",num2);
|
||||||
|
|
||||||
|
//loops
|
||||||
|
let mut loop_cycles = 1;
|
||||||
|
loop {
|
||||||
|
|
||||||
|
println!("this is loop: {}",loop_cycles);
|
||||||
|
if loop_cycles == 3 {break};
|
||||||
|
loop_cycles += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
//loop expression
|
||||||
|
loop_cycles = 1;
|
||||||
|
let result = loop {
|
||||||
|
|
||||||
|
println!("cycle: {}",loop_cycles);
|
||||||
|
|
||||||
|
if 7 % loop_cycles == 2 {break loop_cycles};
|
||||||
|
|
||||||
|
loop_cycles += 1
|
||||||
|
};
|
||||||
|
println!("it took {} cycles to resolve the expression",result);
|
||||||
|
|
||||||
|
//while
|
||||||
|
loop_cycles = 1;
|
||||||
|
while 5 > loop_cycles {
|
||||||
|
if loop_cycles == 2
|
||||||
|
{
|
||||||
|
loop_cycles +=1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
println!("while loop {}",loop_cycles);
|
||||||
|
loop_cycles += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//for loops
|
||||||
|
//1..5 is 1 up to 5 not including 5
|
||||||
|
for x in 1..5
|
||||||
|
{
|
||||||
|
println!("for loop: {}",x);
|
||||||
|
}
|
||||||
|
//1..=5 is 1 up to and including 5
|
||||||
|
for x in 1..=5
|
||||||
|
{
|
||||||
|
println!("for loop including: {}",x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user