From the course: Learning PHP

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

For loops

For loops - PHP Tutorial

From the course: Learning PHP

Start my 1-month free trial

For loops

- [Instructor] For loops are made specifically for enumeration. The starting assignment, the condition, and the incrementer are all in the for loop definition. So you see here, we have the keyword for, and then in parentheses, we have a starting assignment followed by a semi colon, a condition followed by a semi colon, and then the incrementer. So inside the loop, all we need is the code we want to execute. For comparison sake, let's take a look at our while loop again. You can see we have the starting assignment outside the loop. We have the condition in the parentheses and we have the incrementer inside the while loop. The incrementer as you saw can be pretty easy to forget. Now let's write a for loop that does a similar task. We'll write for and then we have the assignment, I gets zero. We have our condition, I is less than 10, and then we have our incrementer. Now it's important to note here that even…

Contents