For Loops, online
Six activities your students do on their own devices. See who's finished, and their scores.
For Loops in one minute
What students need to know
This is the initializer, the first part of the for loop header. A for loop has an initializer, condition, and update, each separated by ;.
JavaScript is case-sensitive, so 'for' must be lowercase. The ++ operator adds one to the loop counter each time.
Mistakes students make
- 'for' must be lowercase - a capital F causes an error.
- The loop header needs parentheses: for (...).
- The three parts of a for loop are separated by semicolons, not commas.
- Code blocks use curly braces {}, not square brackets [].
What students will learn in this module
Every question in Module 20
Quick questions
- Does a for loop have three parts separated by semicolons?AYesBNo
- Must 'for' be written in lowercase?ANoBYes
- Does i++ increase i by 1 after each pass?ANoBYes
- Can a for loop count down using i--?AYesBNo
- Are the three parts of a for loop separated by commas?ANoBYes
Key terms
Students type the meaning of:
for
Match the pairs
for (let i = 1; i <= 3; i++) { ... }Match it to what it doesfor (let j = 5; j > 0; j--) { ... }Match it to what it doesSets the loop counter's starting valueMatch it to what it doesIncreases i by 1 after each pass through the loopMatch it to what it doesfor let i = 1; i <= 3; i++ { ... }Match it to what it doesfor (let i = 1, i <= 3; i++) { ... }Match it to what it doesFill in the blanks
___ (let i = 1; i <= 3; i++) {Hint: Type the keyword that starts a for loop.
for (let i = 1; i __ 3; i++) {Hint: Type the operator that checks less than or equal to.
for (let i = 1; i <= 3; i__) {Hint: Type the operator that adds one to i after each pass.
for (let j = 5; j > 0; j__) {Hint: Type the operator that subtracts one from j after each pass.
for (___ k = 0; k < 4; k++) {Hint: Type the keyword used to declare the loop counter.
Spot the error
Question 1
AFor (let i = 1; i <= 3; i++) {Bconsole.log(i);C}
Question 2
Aconsole.log(i);Bfor let i = 1; i <= 3; i++ {C}
Question 3
Alet total = 0;Bconsole.log(total);Cfor (let i = 1, i <= 3; i++) {
Question 4
Aconsole.log(i);Bconsole.log(x);Cconsole.log(y);Dfor (let i = 1; i <= 3; i++) [
Question 5
Afor (let i = 0; i < 5; i++) {Bconsole.log(i)C}
