break
break
is a keyword available for use inside of a while
loop and it is used to exit out of the loop before the looping condition is met.
let mut counter = 0;
while counter < 10 {
counter += 1;
if 5 < counter {
break;
}
}
In the example above the while
loop is set to iterate until counter
reaches the value of 10
however the if expression will break out of the loop once counter
reaches the value of 6
.