Advance C++


break and continue statement tutorials
-
break and continue statement is use for, do, do..while loop for all iterations.
-
In normal operation, loop is terminated when condition become false.
-
Inside a loop flow can be controlled using break and continue.
-
Loop block continue various statements. When program executes continue statement, it will skips over the rest of statement in the loop, and control goes on to the beginning of loop.
-
Inside loop block, when program control executes break statement, the current loop is terminated abruptly, it comes out of loop forever. This feature is used within loop for two termination points. One when condition is false and second when it comes across break statement within loop.
Syntaxfor (loop …..){Statement;Statement;if (some condition)continue;if (some condition)break;Statement;Statement;} |
|
C++ Program to explain continue and break statement |
|
|
// Program to explain continue and break statement#include<iostream.h>main(){int no;for(no=1;no<=10;no++){if(no==5)continue;if(no==8)break;cout<<no<<"\n";}} |
Output |
123467 |