Advertisement
Difference between Break and Continue | Break vs. Continue
Difference between Break and Continue
Break |
Continue |
| Break is used to terminate the execution of the loop. | Continue is not used to terminate the execution of loop. |
| It breaks the iteration. | It skips the iteration. |
| When this statement is executed, control will come out from the loop and executes the statement immediate after loop. | When this statement is executed, it will not come out of the loop but moves/jumps to the next iteration of loop. |
| Break is used with loops as well as switch case. | Continue is only used in loops, it is not used in switch case. |
| Example : <?php for($A=1 ; $A<=5 ; $A++)
{
if($A > 3)
{
break;
}
echo “ ” ,$A;
}
?> Output : 1 2 3 |
Example : <?php for($A=1 ; $A<=5 ; $A++)
{
if($A == 3)
{
continue;
}
echo “ ” ,$A;
}
?> |
