Loop in PHP - while loop


There is three main loop in PHP: 

  • while
  • for
  • foreach


while:

  while(condition)
{
do this
}


###################################
PHP Code
###################################

<html>
<head>
<title>Loop Example</title>
</head>

<body>

<?php


/*
one way of using loop:
in this Program will check condition First and
execute block of code within it, if the condition is true

*/

echo " <br/> ";

$i = 0;
while( $i < 10)
{
echo $i;
echo " <br/> ";
$i++;   // will increment i with 1
}


echo " <hr/> ";


$j = 0;
do
{
echo $j;
echo " <br/> ";
// will increment j with 1
$j++;
}
while ( $j < 10 )

?>

</body>

</html>

Comments

Popular posts from this blog

Page Unload Show Notification to user

Function Oriented File Upload PHP

Upload File Using PHP - Example For Image