Membership
Main Menu
Forum Boards
Stats
- 18 tutorials
- 72,337 members
- 696,790 forum posts
- 11 blog posts
Tutorials
PHP Loops
Views: 21564
Show Me The Money!
The Instruction
The Instruction is what you want PHP to do each iteration of your loop. It can be something as simple as echoing out the current iteration, doing some math based on each iteration, or pulling out a new row of information from a database. This is the "pattern," or "common denominator" to your large chunk of code/content. It's the individual brick that your loop stacks over and over to make your wall.
The most challenging part of making a loop is the Instruction part. Finding the pattern isn't always so easy as our simple condition to test if a number divides evenly by another number. You can use virtually anything inside your loop to build your pattern, from regular assignments/outputs to conditions; you can even put another loop inside your loop! And there's really no limit to how far you can "nest" things inside one another, except for how far you can wrap your head around the logic. Finding a pattern to make a loop out of deserves it's own tutorial altogether. It is what makes looping an artform.
