Break statement is a loop control statement which is used to terminate the loop.Break statement terminates the control of inner loop only.
#include void main() { int i=1; for(i=1;i<=10;i++) { cout<<"This Is No\n"<< i ; if(i==5) { break; } } }
output:-
This Is No 1
This Is No 2
This Is No 3
This Is No 4
This Is No 5
loop from 1 to 10 is not printed after i==5
Continue is also a loop control statement which is used to execute the next iteration of the loop.When the continue statement is executed in the loop, the code inside the loop following the continue statement will be skipped and next iteration of the loop will begin.
#include void main() { int i=1; for(i=1;i<=8;i++) { if(i==3) { continue; } cout<<"This Is No\n"<< i ; } }
output:-
This Is No 1
This Is No 2
This Is No 4
This Is No 5
This Is No 6
This Is No 7
This Is No 8