Java break and continue
Break statement :
The break statement is used to exit the loop irrespective of whether the condition is true or false.
Whenever a ‘break’ is encountered inside the loop, the control is sent outside the loop.
Example to demonstrate the use of break inside a for loop :
Flow control of break statement :
Continue statement :
The continue statement is used to immediately move to the next iteration of the loop.
The control is taken to the next iteration thus skipping everything below ‘continue’ inside the loop for that iteration.
Example to demonstrate the use of continue statement inside a for loop :
Flow control of continue statement :
In a Nut Shell …
1.break statement completely exits the loop
2.continue statement skips the particular iteration of the loop.