Get latest news and Web Designing tutoria

Saturday, 30 May 2015

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

Related Posts:

  • PHP For Loops So what’s a loop then? A loop is something that goes round and round. If I told you to move a finger around in a loop, you’d have no problem with the order (unless you have no fingers!) In programming, it’s exactly … Read More
  • PHP and HTML Radio Buttons Make sure you save your work as radioButton.php, as that's where we're posting the Form – to itself. To get the value of a radio button with PHP code, again you access the NAME attribute of the HTML form elements.… Read More
  • PHP While Loops Instead of using a for loop, you have the option to use a while loop. The structure of a while loop is more simple than a for loop, because you’re only evaluating the one condition. The loop goes round and round whi… Read More
  • PHP and HTML Checkboxes Note one thing about the HTML checkbox elements: they all have different NAME values (ch1, ch2 ch3, etc). When we coded for the Radio Buttons, we gave the buttons the same NAME. That's because only one option can be se… Read More
  • The HTML ACTION attribute and PHP You don't have to submit your form data to the same PHP page, as we've been doing. You can send it to an entirely different PHP page. To see how it works, try this: Create the following page, and call it basicForm2.ph… Read More

0 comments:

Post a Comment