Every break within a loop must return the same type. In Rust, break statement inside any loop gives you way to break or terminate the execution of loop containing it, and transfers the execution to the next statement following the loop.
Next, we have an if statement that checks the variable ctr is equal to 5, if it returns TRUE causes loop to break or terminate. In Rust, sometimes you may encounter situations where you have nested loops, in such case you are required to specify the loop which one your break statement is applicable for.
The standard unlabeled break statement is used to terminate the nearest enclosing loop. In Rust, there is another form of break (labeled break) statement is used to terminate specified loop and control jumps to the statement immediately following the labeled statement.
Loops in Rust aren’t the same as standard C-style languages. The syntax is different and there are some powerful options that make looping easier.
By using the label ‘outer we are able to control explicitly which loop is broken. Making statements based on opinion; back them up with references or personal experience.