Membership
Main Menu
Forum Boards
Stats
- 20 tutorials
- 74,814 members
- 734,888 forum posts
- 13 blog posts
Tutorials
PHP Loops
by Crayon Violent on Jun 19, 2008 2:46:30 PM
Views: 25161
Let's Get Loopy
All loops are broken down into four basic pieces:
- The initialization
- The condition
- The instruction
- The iteration
A basic "for" loop looks like this:
for (initialization; condition; iteration) {
instruction
}
We start out with telling PHP what kind of loop it is. Since it is a "for" loop, we start out by simply saying "for ..." The initialization, condition, and iteration are put inside the ( )'s, separated by a semicolon. We use { } brackets to show where the start and end of our instruction is. Some people like to put the { on its own line like this:
for (initialization; condition; iteration)
{
instruction
}
It's really just a matter of style; PHP doesn't care either way.
Comments
1. Ben Smithers on Jun 20, 2008 5:07:40 AM
2. Crayon Violent on Jun 20, 2008 10:19:46 AM
3. kahratka on Jun 20, 2008 10:32:40 AM
Login or register to post a comment.
