From the course: PHP Essential Training
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
For loops - PHP Tutorial
From the course: PHP Essential Training
For loops
- In this movie, we'll look at for loops. For loops are very similar to while loops. They repeat a section of code until a condition is met. But the syntax used for doing it is very different. Why have both then? Well, probably because for loops are the most classic kind of loop that there is and they're used in many other programming languages and some people prefer the more complex syntax of for loops. Let's take a look at that syntax now. A for loop looks very similar at first except for the expression part. Instead of having one expression in parentheses we're going to have three separated by semicolons and each one's going to perform a different function. Expression one is going to be executed the first time only it's like initializing statement before the loop starts. Expression two is the test expression. That's going to be checked at the start of each loop. Just like the expression that we had in the while loop…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.