Locked lesson.
About this lesson
How to use For Loops.
Exercise files
Download this lesson’s related exercise files.
For Loops.docx58.8 KB For Loops - Solution.docx
59.1 KB
Quick reference
For Loops
For loops are another type of loop.
When to use
For loops can be used for most looping things.
Instructions
A FOR loop has this general format:
for (initial counter; conditional; increment) {
// do something;
}
You don't need to increment your counter inside the loop.
Here's an example:
for ($x = 0; $x < 10; $x++) {
echo "Your Number is $x <br/>";
}
Hints & tips
- For loops use less code than while loops
- You don't have to increment for loops inside the counter
Lesson notes are only available for subscribers.