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 [].

Discover other journeys with this module

What students will learn in this module

Every question in Module 20

Quick questions

  1. Does a for loop have three parts separated by semicolons?AYesBNo
  2. Must 'for' be written in lowercase?ANoBYes
  3. Does i++ increase i by 1 after each pass?ANoBYes
  4. Can a for loop count down using i--?AYesBNo
  5. 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 does
for (let j = 5; j > 0; j--) { ... }Match it to what it does
Sets the loop counter's starting valueMatch it to what it does
Increases i by 1 after each pass through the loopMatch it to what it does
for let i = 1; i <= 3; i++ { ... }Match it to what it does
for (let i = 1, i <= 3; i++) { ... }Match it to what it does

Fill in the blanks

  1. ___ (let i = 1; i <= 3; i++) {

    Hint: Type the keyword that starts a for loop.

  2. for (let i = 1; i __ 3; i++) {

    Hint: Type the operator that checks less than or equal to.

  3. for (let i = 1; i <= 3; i__) {

    Hint: Type the operator that adds one to i after each pass.

  4. for (let j = 5; j > 0; j__) {

    Hint: Type the operator that subtracts one from j after each pass.

  5. 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}