Enter your Sign-on user name and password.

Forgot password?
  • Follow us on:
Loading video...

Start Learning Now

Our free lessons will get you started (Flash® 10 required).
Get immediate access to our entire library.

Sign up for Educator.com

Features Overview

  • Get on-demand access to our complete library
  • Search and jump to exactly what you need to learn
  • Track your progress
  • Download practice and lesson files
  • *Ask questions and get answers from our community & instructors

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.

Computer Science: Introduction to PHP