Loop loop
This commit is contained in:
+8
-2
@@ -1,9 +1,15 @@
|
||||
fn main() {
|
||||
let mut counter = 0;
|
||||
|
||||
// While loop is as expected
|
||||
while counter < 23 {
|
||||
// Infinite loop in Rust
|
||||
loop {
|
||||
println!("In the loop: {}", counter);
|
||||
counter += 1;
|
||||
|
||||
if counter == 23 {
|
||||
// Break can be used to exit the loop
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
println!("Counter is {}", counter);
|
||||
|
||||
Reference in New Issue
Block a user