Computer Science, asked by kritikuku31, 1 year ago

difference between continue and break statement

Answers

Answered by kashish123456
0
continue: persist in an activity or process.

break: separate into pieces as a result of a blow, shock, or strain.

kritikuku31: thanku
uneq95: lol...what is this answer...
Answered by uneq95
1
see the code:

for(int i = 0; i<5 ;i++){
print "sumita"
}
print "sumita" is just a print statement i have assumed..replace it with the print statement of your specific language.
This code will print sumita 5 times.
_____________________________
for(int i = 0; i<5 ;i++){
if(i==3){break;}

print "sumita"
}

In this code the loop will run and when the value of i becomes 3, we have to executive the break statement.
what break statement will do is that it wont let other iterations to occur, ie, the control will come out of the loop.
so this code will print sumita only 3 times.
_________________________________

for(int i = 0; i<5 ;i++){
if(i==3){continue;}
else print "sumita"
}
in this code, the code will print sumita for values of i= 0,1,2 and then the value of i becomes 3. after i becomes 3, it will execute the continue statement and go on for the next iteration ie for i = 4.
Hence the code will print sumita for i= 0,1,2, skips printing for i=3,then again prints for i=4 and then loop stops.
____________________
In short,

whenever the break is execute, the control comes out of the loop without carrying on any more iterations.

whenever the continue statement is executed, the, the control moves on to the next iteration without executing any lines below the continue in the loop.
Similar questions