Loading video...
Introduction to Conditional Loops
- A while loop is a conditional control structure that executes a statement group repeatedly as long as its specified test condition remains TRUE .
- A while loop’s test condition’s value is compared to TRUE before each execution of the loop’s statement group.
- 'Looping over arrays' is a common programming function, and PHP provides several
built-in functions for doing so. They work on the basis of an array cursor ,
which is a 'marker' for the 'current' array element:
- current() – returns the value of the array element at the current array cursor position
- key() – returns the key of the array element at the current array cursor position
- next() – advances the array cursor by one
- prev() – moves the array cursor back by one
- reset() – sets the array cursor to the 1st element
- end() – sets the array cursor to the last element
- The list() construct and the each() function are also used to loop over arrays.
- list() is used to assign values to multiple variables at a time from an indexed array.
- each() returns key/value information for the current array element in an array and advances the array cursor by one. It returns FALSE if the end of the array is reached.
- Unlike some programming languages, PHP does not have ‘block-level’ scope used with control structures.
- Additional Resources:
Introduction to Conditional 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.
- Intro
- Lesson Overview
- while Loop
- Looping Over Arrays
- Looping Over Arrays (cont.)
- Array Traversal Functions
- Indexed Arrays: Using current () and next ()
- Associative Arrays: Using key (), current (), and next ()
- Array Traversal Functions (cont.)
- Lopping Over Arrays Using list(), each()
- Control Structure Scope
- Coding Conventions
- Homework Challenge

































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