PHP Loop continue

Source: Internet
Author: User

The number of times specified in the code block executed by the PHP loop continue, or if the specified condition is true.


-------------------------------------------------- ------------------------------

For loops
The loop is used when you know in advance how many times the script should run.

Grammar

for (init; condition; increment)
{
code to is executed;
}

Parameters:

Initialization: Primarily used to set a counter (but can be any code execution at the start of a loop)
Conditions: Evaluates each iteration of the loop. If the value is true, the loop continues. If the value is False, the loop ends.
Increment: Used primarily to add a counter (but can be any code that will execute at the end of the loop)
Note: The above can be empty, or there are multiple expressions for each argument (separated by commas).

For example
The following example defines a loop, which begins with i = 1. The loop will continue to run as long as I am less than or equal to 5. I'm going to add 1 each time the loop runs:

<body>

<?php
For ($i =1 $i <=5; $i + +)
{
echo "The number is". $i. "<br/>";
}
?>

</body>

The number is 1
The number is 2
The number is 3
The number is 4
The number is 5

Example Two

<?php
while (the list ($key, $value) = each ($arr)) {
if (!) ( $key% 2)) {//Skip odd members
Continue
}
Do_something_odd ($value);
}

$i = 0;
while ($i + + < 5) {
echo "Outer<br/>n";
while (1) {
echo "&nbsp;&nbsp; Middle<br/>n ";
while (1) {
echo "&nbsp;&nbsp;inner<br/>n";
Continue 3;
}
echo "This never gets output.<br/>n";
}
echo "Neither does this.<br/>n";
}
?>

<?php
for ($i = 0; $i < 5; + + $i) {
if ($i = = 2)
Continue
print "$in";
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.