The while statement
loops on a code block as long as a condition is true.
The following code loops until n reaches the value 10:
let mut n = 1;
while n < 10 {
print!("{n}, ");
n += 1;
}()As for the loop statement:
The
continuekeyword is used to skip a step.The
breakkeyword is used to exit the loop prematurely.Labels are used to exit nested loops.