In this lesson our instructor talks about for and foreach loops. First, he discusses for loops, looping over indexed arrays with a for loop, and foreach loops. Then he talks about indexed array syntax, associative array syntax, and some coding conventions. He ends the lesson with a helpful homework challenge.
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
the 2nd expression is the test condition for the loop, whose value is
compared to TRUEbefore 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
Both continue and break statements work within for and foreach
loops just as they do in while and do-while 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.