+ 9
Is break and continue same?
explain more?
7 Respostas
+ 7
Example:
1.Continue
for (int a=0;a<=10;a++){
if (a%2==1){
continue;}
System.out.print(a);
}
//Output:02468
2.Break
for (int a=0;a<=10;a++){
if (a%2==1){
break;}
System.out.print(a);
}
//Output:0
+ 7
The break statement exits from the loop, ending the loop cycle. Continue simply goes to the next iteration of the loop.
+ 5
break ends the loop, continue only ends the current iteration.
while(true) break;
while(true) continue;
The first line will be executed once, the other one is an infinite loop.
+ 5
well both are used in loops but they vary in purpose
1-break is used to exit the loop when certain condition is reached
2-continue is used to skip the rest of loop statements and goes back to the start of the loop
+ 4
The break statement terminates the loop (code block) immediately when it is encountered. The continue statement just skip the current iteration of loop, and loop start new iteration after checking loop condition.
+ 3
no pal, both aren't same,
break statement is used to terminate the loop when your desire case comes out.
eg : I wish to stop the loop on 5th iteration,
for(I=1;I <=10;I++)
if(I==5)
break;
cout << I << " ";
output will be : 1 2 3 4
it's the job of break statement.
the continue statement, is useful to skip the just current loop iteration not to terminate the loop.
for(I=1;I <=10;I++)
if(I==5)
continue;
cout << I << " ";
output will be : 1 2 3 4 6 7 8 9 10
you can see, we missed 5 here for the same program.
I hope you will got the difference.
+ 2
No. They are not same. Break stops, terminates loop and continue skips iteration. Take a look at this https://www.sololearn.com/Discuss/873950/?ref=app