Register now or log in to join your professional community.
he break statement allows you to exit a loop from any point within its body, bypassing its normal termination expression. When the break statement is encountered inside a loop, the loop is immediately terminated, and program control resumes at the next statement following the loop. The break statement can be used with all three of C's loops. You can have as many statements within a loop as you desire. It is generally best to use thebreak for special purposes, not as your normal loop exit. break is also used in conjunction with functions andcase statements which will be covered in later sections.
The continue statement is somewhat the opposite of the break statement. It forces the next iteration of the loop to take place, skipping any code in between itself and the test condition of the loop. In while and do-whileloops, a continue statement will cause control to go directly to the test condition and then continue the looping process. In the case of the for loop, the increment part of the loop continues. One good use of continue is to restart a statement sequence when an error occurs.
#include $$$$stdio.h&&&&
Break leaves the loop completely and executes the statements after the loop. Whereas Continue leaves the current iteration and executes with the next value in the loop.
in short, 'break' statement does a permanent exit from the loop.
while 'continue' makes the current iteration of the loop to be bypassed to the next iteration
Thank you for the invitation
A break statement results in the termination of the statement to which it applies ( switch , for , do , or while ). A continue statement is used to end the current loop iteration and return control to the loop statement.
Following code explain the concept
I am not showing you output because if you try to run it by yourself you got better understanding
public static void main(String[] args) {
for(int i=0;i<;i++){
if (i==4){
break;
}
System.out.print(i+"\\t");
}
System.out.println();
for(int i=0;i<;i++){
if (i==4){
continue;
}
System.out.print(i+"\\t");
}
}
Break : Terminates the loop or switch statements and transfers excution to immediately loop or switch.break the peresent loop or swtich and jump to following next loop or switch.
continue : the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
The break statement breaks the loop and continues executing the code after the loop (if any)The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.
The `break` statement is used in switch or loops and `continue` statement is used only in loops. When break statement is encountered it immediately stops the switch or loop execution. When continue statement is encountered, all the statements next to it are skipped and the loop control goes to next iteration.