Home Tutorial Php Phpbeginners Do..While Loops

 
 

Do..While Loops
Posted on: July 10, 2009 at 12:00 AM
Advertisement
The do...while statement always execute the block of code once, then check the condition, and repeat the loop until the condition is true.

3.10.2. Do…While Loops

The do...while statement always execute the block of code once, then check the condition, and repeat the loop until the condition is true.

Syntax

do

{

code to be executed;

}

while (condition);

e.g.

Here we define i = 1, and then increment i with 1. The code first execute i=1+1, print 2; then it checks the further condition. The loop continues until i reaches to either 5 or less than 5.

<?php

$i=1;

do

{

$i++;

echo “The number is “ . $i . “<br />”;

}

while ($i<=5);

?>

Output:

The number is 2

The number is 3

The number is 4

The number is 5

The number is 6

Advertisement

Related Tags for Do..While Loops:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 10, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com