KnowledgeBoat Logo

Computer Applications

How are these statements different from each other:

(i) break

(ii) continue

(iii) System.exit(0)

Java Iterative Stmts

5 Likes

Answer

(i) The break statement terminates the current loop or switch statement. The execution then continues from the statement immediately following the current loop or switch statement.

(ii) The continue statement tells the computer to skip the rest of the current iteration of the loop. However, instead of jumping out of the loop completely like break statement, it jumps back to the beginning of the loop and continues with the next iteration. This includes the evaluation of the loop controlling condition to check whether any further iterations are required.

(iii) Unlike break and continue statements which are used to control the flow of execution, System.exit(0) command terminates the execution of the program by stopping the Java Virtual Machine which is executing the program. It is generally used when due to some reason it is not possible to continue with the execution of the program.

Answered By

2 Likes


Related Questions