-
Step 1
The "while" statement starts with the word "while" followed by the condition you are checking set in parenthesis, then an opening curly brace indicating the code to follow is within the loop. So the code looks like this:
While (condition) { -
Step 2
After the opening line it's time to type in your code. This represents that you want to keep executing the code so as long as the condition in the first line is true. So your code could look like this:
$i=0;
while ($i<10) {
$i++;
The code above uses a variable called $i. As long as $i is less than 10 the code $i++ will continue to execute. That code adds 1 to the value of $i. -
Step 3
The last line of code is a closing curly brace to indicate that code after that brace is not included within the loop. So the final code looks like this:
$i=0;
while ($i<10) {
$i++;
}
Note: Somewhere in your loop your condition must eventually evaluate to flase otherwise you will end up in an infinite loop.










