Break is used with loops as well as switch case. Continue is only used in loops, it is not used in switch case. Break ends a loop completely, continue just shortcuts the current iteration and moves on to the next iteration.
1 2 3 4 | while ($foo) { <--------------------┐ continue; --- goes back here --┘ break; ----- jumps here ----┐ } |
This would be used like so:
1 2 3 4 5 6 7 8 | while ($droid = searchDroids()) { if ($droid != $theDroidYoureLookingFor) { continue; // ..the search with the next droid } $foundDroidYoureLookingFor = true; break; // ..off the search } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.