Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between break and continue statement

Can anyone tell me the difference between break and continue statements?

like image 934
DonX Avatar asked Jan 20 '09 18:01

DonX


People also ask

What is the difference between break and continue with valid example?

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.

What is the difference between break and continue in a loop?

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.

What is difference between break and control statements in C?

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.


2 Answers

break leaves a loop, continue jumps to the next iteration.

like image 83
Xn0vv3r Avatar answered Oct 18 '22 20:10

Xn0vv3r


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.

like image 29
Jay Avatar answered Oct 18 '22 21:10

Jay