+ 1

What is difference between break and continue statements in c++?

30th Nov 2016, 3:53 PM
Fahmeen Mazhar
Fahmeen Mazhar - avatar
4 Antworten
+ 1
break: Break out of the current loop and proceed to the next line of code continue: Go back to the loop statement and iterate (i.e. using this, one can skip the code for some specific value of a variable) Example for continue: for(a=1;a<=5;a++) { if(a==3) { continue; } cout<<a; } The above code will print all integers from 1 to 5 except 3 because the continue statement forced the program to skip the code below and continue iteration/looping.
30th Nov 2016, 4:05 PM
PythonProMaybe
+ 1
Break will terminate your statement (switch, for, do, while). Continue will skip your statement. eg, for(i=1; i<=5; i++){ if(i == 2){ continue; } if(i == 4){ break; } cout << i; } will return : 13
30th Nov 2016, 4:06 PM
Fendi Septiawan
Fendi Septiawan - avatar
+ 1
Break 'breaks out' (leaves) the looping block as if it were the LAST thing for the loop to do. Continue is like break, except it jumps immediately to the NEXT loop iteration (conditions are tested and so of course it may also exit the loop).
30th Nov 2016, 5:38 PM
Kirk Schafer
Kirk Schafer - avatar
0
The major difference between break and continue statements in C language is that a break causes the innermost enclosing loop or switch to be exited immediately. Whereas, the continue statement causes the next iteration of the enclosing for , while , or do loop to begin.
30th Nov 2016, 9:23 PM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar