O'Reilly logo

PHP for Teens by Maneesh Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loops

Sometimes, while designing a program, you need to execute a set of statements repeatedly. You might need to display an entire set of data with hundreds of elements or list all numbers from 1 to 100. Fortunately, PHP offers loops, which allow you to execute a set of statements as many times as needed. There are several different types of loops. Each type has strengths and weaknesses. You most often find loops with arrays, which I go over in Chapter 10.

while

Let’s start off with the most common loop: while. Using the while loop, you execute the statements as long as a certain condition is true. Remember the three stages of the while loop:

  • Initialization outside the loop, which ensures the loop executes at least once

  • Condition inside the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required