1.10. Repeating Code

The last type of functionality in this brief introduction is looping. Looping allows you to repeat the execution of code. Listing 1.12 is an example of a for loop. The for statement expects three parameters separated by semicolons. The first parameter is executed once before the loop begins. It usually initializes a variable. The second parameter makes a test. This is usually a test against the variable named in the first parameter. The third parameter is executed every time the end of the loop is reached (see Figure 1.5).

Listing 1.12. Today's daily affirmation
 <html> <head> <title>Listing 1-12</title> </head> <body> <h1>Today's Daily Affirmation</h1> Repeat three times:<br> <?php for($count = 1; $count <= 3; $count++) ...

Get Core PHP Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.