You may recall encountering the break
statement in a previous chapter of this tutorial, where it was utilized to exit a switch statement abruptly.
The break statement is also employed to exit a loop prematurely.
In this example, the loop halts when the value of ‘i’ reaches 4:
|
The continue statement interrupts the current iteration within the loop if a specific condition arises and proceeds with the next iteration.
This example omits the assess of 4:
|
You can employ both break and continue within while loops:
|
|