PHP - English

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) {

break;

}

$counter++;

}

Try the code out and see what happens.

Ok, that’s enough of loops. For now. In the next section, we’ll take a look
at what arrays are, and how useful they can be. (Yes, there’ll be loops!)

|

Kaynak : https://www.homeandlearn.co.uk/php/php5p6.html ‘sitesinden alıntı

Yorum Yap