+ 1
Difference between break and continue?
4 points ....
3 odpowiedzi
+ 3
for(...) {
// instructions ... <---+
if(some_condition) |
continue; -------------+
if(some_condition)
break; ------------------+
} |
// instructions <-----------+
continue means to go back and execute the first instruction within loop body.
break means to break out (jump out of) the loop body and execute next instruction following the loop body (if there was any)
Hth, cmiiw
+ 2
break will exit the loop.
continue skips the remaining code in the current iteration of the loop then continues looping
+ 1
Break leaves the loop completely and executes the statements after the loop. Whereas Continue leaves the current iteration and executes with the next value in the loop. ... A continue statement is used to end the current loop iteration and return control to the loop statement.
BASIS FOR COMPARISON BREAK CONTINUE
Task
It terminates the execution of remaining iteration of the loop. It terminates only the current iteration of the loop.
Control after break/continue 'break' resumes the control of the program to the end of loop enclosing that 'break'. 'continue' resumes the control of the program to the next iteration of that loop enclosing 'continue'.
Causes It causes early termination of loop. It causes early execution of the next iteration.
Continuation 'break' stops the continuation of loop. 'continue' do not stops the continuation of loop, it only stops the current iteration.
Other uses 'break' can be used with 'switch', 'label'. 'continue' can not be executed with 'switch' and 'labels'.