Header

break and continue

break and continue statement

It is sometimes desirable to skip some statements inside the loop or terminate the loop immediately without checking the test expression. In such cases we can use break statements in Java. Please note that Java does not provide Go To statement like other programming languages e.g. C, C++ (The Java keyword list specifies the goto keyword, but it is marked as "not used").

Break statement

The break statement is used with the conditional switch statement and with the do, for, and while loop statements. When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.

 

Differentiate between break and continue statements

Differentiate between break and continue statements.

break

continue



It terminates the execution of remaining iteration of the loop.

It terminates only the current iteration of the loop.



'break' resumes the control of the program to the end of loop enclosing that 'break'.


'continue' resumes the control of the program to the next iteration of that loop enclosing 'continue'.

It causes early termination of loop.

It causes early execution of the next iteration.

'break' stops the continuation of loop.

'continue' do not stops the continuation of loop, it only stops the current iteration.

'break' can be used with 'switch', 'label'.

'continue' can not be executed with 'switch' and 'labels'.





No comments

Theme images by 5ugarless. Powered by Blogger.