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:
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!)
$TeacherInterrupts = true;
$counter = 1;
$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!)
0 comments:
Post a Comment