Do … while loop

Do … while loop

The commands contained in the loop will be executed at least once – in the case of the while loop need not be so. If the first time the condition is not fulfilled the commands of the loop will never be executed. In the case of the loop they will be executed at least the first time.
Example

<?php

do {

instructions

} While (condition);

?>

 

Interrupting performances loop

Sometimes you need to break a given iteration (repeat) loop and move on to the next iteration. This is done continue statement. Just insert it in the right place inside the loop.

Example

<?php

for ($x = 1; $x <= 100; $x ++) {

if ($ x% 2! = 0)
continue;

echo $x. ”
}

?>

After running we should see even numbers from 1 to 100.
There is also a command that causes the total output of the loop. This command is the         ” break”.

Example

<?php

for ($x = 0; $x <10; $x ++) {
if ($x% 2 == 0)
echo $x. ”
if ($name == „Test”)
break;
}

?>

Cookies help us deliver our services. By using our services, you agree to our use of cookies. More Info | Close