The break statement
Loops help iterateing over from the start till it arives on a vector data type. However, there are times when you would like to stop the iteration in between and jump out or exit from the loop without executing the conditional test again. The break
statement helps us do that. It helps us terminate the loop by passing the control to the first instruction after the loop.
In the following screenshot example, the for
loop is terminated and control moves out of the for
loop when the value of i
is 1
because of the use of the break
statement. It literally breaks the loop as shown in the following screenshot: