Locked lesson.
About this lesson
Looping through things using For loops.
Exercise files
Download this lesson’s related exercise files.
For Loops.docx58.9 KB For Loops - Solution.docx
59 KB
Quick reference
For Loops
For loops allow us to loop through conditions.
When to use
Use a For loop any time you want to loop through a condition and take some action.
Instructions
The basic struction of a For loop is this:
for (statement1; statement2; statement3) {
//do something
}
Statement 1 is the initial counter variable.
Statement 2 is the condition we'll be testing against.
Statement 3 does something to the counter (increases it or decreases it).
example:
for (i = 1; i < 10; i++){
document.write(i + " is less than 10...<br/>");
}
Hints & tips
- For loops are a great way to loop through conditions
Lesson notes are only available for subscribers.