Jump to: navigation, search

Php while

From w3cyberlearnings

Contents

while condition

while loops check the expression, and when the expression meets the condition then the statement executes.

Syntax while

while(expre)
 statement

Example 1

<?php

$n = 5;
$i = 0;
while ($i <= 5) {
	echo $i++;
}
?>


Output

012345

Example 2

<?php

$i = 1;

echo '<table border="1">';
echo '<tr><th>#</th></tr>';
while ($i <= 5) {
	echo '<tr><td>' . $i . '</td></tr>';
	$i++;
}
echo '</table>';
?>

Output

#
1
2
3
4
5


Related Links


Navigation
Web
SQL
MISC
References