While Loops, online

Six activities your students do on their own devices. See who's finished, and their scores.

While Loops in one minute

What students need to know

This line moves count closer to making the condition false. This happens when the loop variable is never updated properly.

The loop keeps running until the condition becomes false. JavaScript is case-sensitive, so 'while' must be lowercase.

Mistakes students make

  • 'while' is misspelled as 'Wile'.
  • The condition needs parentheses: while (n > 0).
  • This line is missing a semicolon, but that's not required in JS.
  • 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 19

Quick questions

  1. Does a while loop repeat as long as its condition is true?AYesBNo
  2. Must 'while' be written in lowercase?ANoBYes
  3. Does a while loop's condition need to be in parentheses?AYesBNo
  4. Can forgetting to update a variable cause an infinite loop?AYesBNo
  5. Does a while loop's code block use curly braces?ANoBYes

Key terms

Students type the meaning of:

  • while

Match the pairs

while (count <= 3) { ... }Match it to what it does
while (isRunning) { ... }Match it to what it does
Updates a variable so the loop eventually stopsMatch it to what it does
Runs forever because the condition never becomes falseMatch it to what it does
while n > 0 { n = n - 1; }Match it to what it does
while (z = 3) { z = z + 1; }Match it to what it does

Fill in the blanks

  1. _____ (count <= 3) {

    Hint: Type the keyword that starts a while loop.

  2. while (count __ 3) {

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

  3. while (n > 0) {
    n = n _ 1;
    }

    Hint: Type the operator that subtracts one from n.

  4. _____ (isRunning) {

    Hint: Type the keyword that starts a while loop.

  5. while (i < 5) {
    i = i _ 1;
    }

    Hint: Type the operator that adds one to i.

Spot the error

Question 1

Alet count = 1;BWile (count <= 3) {Ccount = count + 1;

Question 2

Awhile n > 0 {Blet n = 5;Cn = n - 1;

Question 3

Alet i = 0;Bwhile (i < 5) {Cconsole.log(i)

Question 4

Alet x = 10;Bwhile (x > 0) [Cx = x - 1;

Question 5

Alet y = 1;Bwhile (y <= 5) {Cy = y + 1;D]