09 May 2005

The while Statement

The while Statement

The while statement is useful, when you want to loop a code until it's conditions are met.
Syntax :
while (condition)
code ....


Example :
");}
echo "Value is ". $val .". condition not met!
";
$val++;
}
?>
Output of this code is :

Value is 0. condition not met!

Value is 1. condition not met!
Value is 2. condition not met!
Value is 3. condition not met!
Value is 4. condition not met!
Value is 5. condition not met!
Value is 6. condition not met!
Value is 7. condition not met!
Value is 8. condition not met!
Value is 9. condition not met!
Value is 10. condition met!

Above code loops until the value is 10.

No comments: