Membership
Main Menu
Forum Boards
Stats
- 18 tutorials
- 72,338 members
- 696,803 forum posts
- 11 blog posts
Tutorials
PHP Loops
Views: 21565
Raspberry Red, Lemony Lemon, Orangey Orange!
Tucan Sam isn't the only dude offering different kinds of loops. PHP offers four different ways to reiterate pieces of code:
- The while loop
- The do...while loop
- The for loop
- The foreach loop
In principle, each kind of loop has the same basic components and does the same basic thing, but their nuances make it possible to write your code more efficiently, depending on your circumstance. The nuances in the loops are being able to put the loop's components in different orders, or even combining components of the loop.
Changing the order of the components is important to know, because this can and will change the outcome of your loop. For example, some loops or orders will execute the instruction first, then check the condition, so you will always get at least one iteration of the loop.
