Can anyone tell me the difference between break
and continue
statements?
Break statement resumes the control of the program to the end of loop and made executional flow outside that loop. Continue statement resumes the control of the program to the next iteration of that loop enclosing 'continue' and made executional flow inside the loop again.
The one-token statements continue and break may be used within loops to alter control flow; continue causes the next iteration of the loop to run immediately, whereas break terminates the loop and causes execution to resume after the loop.
Difference Between Break and Continue Statements in C: Both break and continue statements are used to alter the flow of execution in a program. These keywords are used in control statements in C programs. The major difference between break and continue is that break is used to end the loop immediately.
break
leaves a loop, continue
jumps to the next iteration.
See Branching Statements for more details and code samples:
break
The break statement has two forms: labeled and unlabeled. You saw the unlabeled form in the previous discussion of the switch statement. You can also use an unlabeled break to terminate a for, while, or do-while loop [...]
An unlabeled break statement terminates the innermost switch, for, while, or do-while statement, but a labeled break terminates an outer statement.
continue
The continue statement skips the current iteration of a for, while , or do-while loop. The unlabeled form skips to the end of the innermost loop's body and evaluates the boolean expression that controls the loop. [...]
A labeled continue statement skips the current iteration of an outer loop marked with the given label.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With