While Loop in PHP


Prev Tutorial Next Tutorial

While Loop in PHP

The while loop is used when you don't know how many times the script should run. while loops execute a block of code while the specified condition is true same like for loop.

Syntax

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

Example of while Loop in PHP

<?php

$n=0;  
while($n<=10)
{  
echo "$n<br/>";  
$n++;  
}  

?>

Output

0 1 2 3 4 5 6 7 8 9 10

Prev Tutorial Next Tutorial

Download Projects

Google Adsense Advertisements
Free Classified Site – Bedpage

Yahoo Advertisements