Loading video...
For & Foreach Loops
- A for loop is a type of conditional loop that requires three
expressions in its definition:
- the 1st expression is evaluated once and only once before the loop begins iteration
- the 2nd expression is the test condition for the loop, whose value is compared to TRUE before each iteration
- the 3rd expression gets evaluated after each iteration of the loop
- A foreach loop is a special type of conditional loop used specifically for iterating over arrays. When using a foreach loop to iterate over an array, the array’s internal cursor is automatically reset by PHP before entering the loop and automatically advanced by one on each loop iteration.
- foreach loops have two syntaxes. One is typically used for iterating over indexed arrays and the other for iterating over associative arrays.
- Both continue and break statements work within for and foreach loops just as they do in while and do-while loops.
- Additional Resources:
For & Foreach Loops
Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

































Start Learning Now
Our free lessons will get you started (Flash® 10 required).
Sign up for Educator.comGet immediate access to our entire library.
Features Overview