PHP loops: while, do while, for

Опубликовано: 03 Октябрь 2024
на канале: Tech World Software School
186
0

Learn PHP loops with NBK Tutor! In this video, you will be learning how to loop using the while loop, the do-while loop, and the for loop! :)

Things to Remember:
For the while loop, FIRST the condition is checked. Then, if that condition is true, the statements get executed. Next, it checks the condition again and repeats the same process. The loop ends when the condition becomes false.
Don't forget to increment/decrement counters within a while loop! Otherwise you will get an INFINITE LOOP, which is not a good idea. ;) You don't want things to keep repeating forever.
The do-while loop FIRST executes the statements within the loop, then checks the condition after the FIRST execution. Then it checks the condition to determine whether to go on with the loop or finish it.
Thus, the do-while loop statements ALWAYS get executed AT LEAST ONCE.
The for loop has three sections: initializer; condition; increment/decrement
The for loop first initializes the counter variable. Then it checks the condition. If that condition is true, the statements within the loop get executed. After all the statements are executed, the counter variable is incremented or decremented. Then the condition is checked to see whether to go on with the loop or finish looping.

My system specs for this video:
Ubuntu 14.04
Apache & PHP 5.5.9