While loop in Php


While loops are used to execute a block of code again and again until a specified condition is true.
In while loop at first initialisation is done. In initialisation we assign any value to a variable.

Syntax of while loop

while(condition)
{
         block of code
}

Example :-
<!DOCTYPE html>
<html>
<head><title>expertcodingmaster.com</title>
</head>
<body>
<?php
/*  suppose we want to print 1-20  */
$i = 1;      // initialisation of varable
while($i<=20)
{
echo $i . "<br>";
$i++;
}
?>
</body>
</html>

Output of the above code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20



No comments: