Home » , , » Do-while loop in php

Do-while loop in php

Written By Unknown on Kamis, 17 Desember 2009 | 09.33

Like while loop Do-while is also used to execute the block of code while the condition is true. 


While loop is a entry controlled loop, but do-while is a exit controlled loop. Because in while loop it will check the condition first and execute the code if the condition is true.

But in do-while loop it will execute the block of codes present inside the “do” and then check the condition.

Syntax:
Do

{
  code to be executed;
}
while (condition);



Example:

$i=1;
do
  {
  $i++;
  echo "The number is " . $i . "
";
  }
while ($i<=5);
?>


Output:


The number is 2
The number is 3
The number is 4
The number is 5
The number is 6
Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger