Page 191 - CITS - Computer Software Application -TT
P. 191
COMPUTER SOFTWARE APPLICATION - CITS
The while loop does not run a specific number of times, but checks after each iteration if the condition is still true.
The condition does not have to be a counter, it could be the status of an operation or any condition that evaluates
to either true or false.
PHP do while Loop
The do...while loop - Loops through a block of code once, and then repeats the loop as long as the specified
condition is true.
Example:
Print $i as long as $i is less than 6:
Note: In a do...while loop the condition is tested AFTER executing the statements within the loop. This means
that the do...while loop will execute its statements at least once, even if the condition is false. See example below.
Let us see what happens if we set the $i variable to 8 instead of 1, before execute the same do...while loop again:
Example:
Set $i = 8, then print $i as long as $i is less than 6:
PHP for Loop
178
CITS : IT&ITES - Computer Software Application - Lesson 47 - 62