PHP while Loop

In PHP there are several different types of loops. Basically what a loop does is evaluate a statement as true or false. If it is true it executes the code and then alter the original statement and start all over again by re-evaluating it. It continues to loop through the code until the statement become false.

Syntax: while (condition is true) { code to be executed; }

Example


<?php
$num = 1;
while ( $num <=10 )
{
	echo $num . '<br />';
	$num++;
}
?>

Basically what this does is: while a number is greater than or equal to 10 it prints the number. The ++ adds one to the number, however this could also be phrased as $num = $num + 1; Once the number becomes greater than 10, in our case it becomes 11, then it stops executing the code within the {brackets}

Combining while loop with a conditional

You can include conditions, MySQL queries, or fire functions inside the loop statement. WHILE loop is closely similar to FOR loop but can be preferably used in case to case conditions.

Example


<?php
$num = 1;
while ( $num <=10 ) {
	if ($num < 5) {
		echo $num . ' is less than 5 <br />';
	} else {
		echo $num . ' is not less than 5 <br />';
	}
$num++;
}
?>

The do…while Loop

do…while loop will always execute the block of code, then it will check the condition, and repeat the loop until the condition become false.

Syntax:
do
{
code to be executed;
}
while (condition is true);

Example


<?php
$num=1;
do
  {
  echo $num . '<br />';
  $num++;
  }
while ($num<=5)
?>

How to take Cialis it seems to me that would already be time to cease to discuss this question. As I already answered it not once. Have it in a look. You shouldn’t worry! All deer go south when they are called by homesickness. Are turned and lie on snow till some hours.