The PHP break statement

The PHP break statement

There are times when you need to break out of a loop before the whole thing gets executed. Or, you want to break out of the loop because of an error your user made. In which case, you can use the break statement. Fortunately, this involves nothing more than typing the word break. Here’s some not very useful code that demonstrates the use of the break statement:

$TeacherInterrupts = true;
$counter = 1;

while ($counter < 11) {

print(" counter = " + $counter + "<BR>");

if ($TeacherInterrupts == true) {





Try the code out and see what happens.

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.