Create a loop with a break statement

This commit is contained in:
Manuel Thalmann 2024-10-16 17:16:14 +02:00
parent fb1df42282
commit 0c0b69835d

View file

@ -1,5 +1,13 @@
fn main() {
loop {
println!("again!");
}
}
let mut counter = 0;
let result = loop {
counter += 1;
if counter == 10 {
break counter * 2;
}
};
println!("The result is {result}");
}