← ACARA Digital Technologies Years 7–8

Using the loop counter inside a for loop

Inside a for loop, the counter i changes on every repeat, so using it in the loop body gives a different value each time, like 1, 2, 3. It only exists inside the loop.

Understanding Using the loop counter inside a for loop in ACARA Digital Technologies Years 7–8

What it does: With let i = 0 the loop prints 0, 1, 2, so the first value of i is 0 rather than 1. Because i is declared with let in the for loop, it only exists inside the loop. The console.log(i) after the loop cannot find it. The counter i goes up by 1 on every repeat, so console.log(i) prints a different value each time: 1, then 2, then 3. On the 3rd repeat i is 3, so i * 7 is 3 * 7 = 21. Starting at 0 would print 0 first, giving 0 to 5. Start at 1 to print 1 to 5.

Common mistakes: The variable is called doubled, not double. Using a name that was never created causes a ReferenceError. It should be console.log(doubled);. This prints 7 on every repeat because it uses the number 7 instead of the answer variable, which changes with i. It should end with + answer);.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 583–598) and word search (Modules 583–613).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What does this code print? for (let i = 1; i <= 3; i++) { console.log(i); }
1, 2, 3 (one number per line)1, 1, 1 (the same number three times)
Matches
for (let i = 1; i <= 5; i++) { console.log("i"); }
↓
i is in quotes, so the text i is printed five times instead of the counter values 1 to 5. Remove the quotes: console.log(i).
Applying
Meanings
Term
console.log(i)
Meaning
Inside a for loop, the counter i changes on every repeat, so using it in the loop body gives a different value each time, like 1, 2, 3. It only exists inside the loop.
Practice
for (let i = 1; i <= 5; i++) {
Testing
Gaps
console.log();
Check Answer
Spots
2 let doubled = i * 2;
3 console.log(double);

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Polar Bear' badge — Data Heavyweight, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What does this code print? for (let i = 1; i <= 3; i++) { console.log(i); }
A. 1, 2, 3 (one number per line) ✓
B. 1, 1, 1 (the same number three times)
The counter i goes up by 1 on every repeat, so console.log(i) prints a different value each time: 1, then 2, then 3.
2. Which loop prints the 7 times table: 7, 14, 21?
A. for (let i = 1; i <= 3; i++) { console.log(7); }
B. for (let i = 1; i <= 3; i++) { console.log(i * 7); } ✓
Using i * 7 in the body gives a new answer on every repeat. console.log(7) prints 7 every time because it does not use the counter.
3. What is the first number printed by this loop? for (let i = 0; i < 3; i++) { console.log(i); }
A. 1
B. 0 ✓
The loop starts with let i = 0, so the first value of i is 0. The output is 0, 1, 2.
4. Which statement about the counter i is true?
A. i holds a different value on each repeat of the loop ✓
B. i keeps the same value for the whole loop
The i++ part updates the counter after each repeat, so the body sees a new value of i every time.
5. Where can you use the variable i from this loop? for (let i = 1; i <= 3; i++) { console.log(i); }
A. Only inside the loop's curly braces ✓
B. Anywhere in the program, including after the loop
A variable declared with let in the for loop is local to the loop. Using console.log(i) after the closing brace gives a ReferenceError.

Match the Pairs

for (let i = 1; i <= 3; i++) { console.log(i); } → Prints 1, then 2, then 3, because the counter i changes on every repeat
for (let i = 1; i <= 5; i++) { console.log(i * 7); } → Prints the 7 times table: 7, 14, 21, 28, 35
Starting the counter at 0 means the first value used in the loop body is 0 → for (let i = 0; i < 3; i++) { console.log(i); }
The counter i is local to the loop, so using it after the loop causes a ReferenceError → for (let i = 1; i <= 3; i++) { } console.log(i);
for (let i = 1; i <= 5; i++) { console.log("i"); } → i is in quotes, so the text i is printed five times instead of the counter values 1 to 5. Remove the quotes: console.log(i).
for (let i = 1; i <= 5; i++) { console.log(7); } → The loop body never uses i, so it prints 7 every time. It should be console.log(i * 7) to get a different answer each repeat.

Key Term

console.log(i)
Inside a for loop, the counter i changes on every repeat, so using it in the loop body gives a different value each time, like 1, 2, 3. It only exists inside the loop.

Fill in the Blanks

1. for (let i = 1; i <= 5; i++) { console.log(i); }
Hint: Type the counter variable name so each repeat prints its current value.
2. for (let i = 1; i <= 12; i++) { console.log(i * 7); }
Hint: Type the arithmetic operator that multiplies the counter by 7 for a times table.
3. for (let i = 0; i < 3; i++) { console.log(i); }
Hint: Type the starting value so the first number printed is zero.
4. for (let i = 1; i <= 3; i++) { console.log(i); }
Hint: Type the keyword that creates the counter so it only exists inside the loop.
5. for (let i = 1; i <= 12; i++) { console.log(`${i} x 7 = ${i * 7}`); }
Hint: Type the counter variable so the times table answer changes on each repeat.

Spot the Error

Question 1
A for (let i = 1; i <= 5; i++) {
B let doubled = i * 2;
C console.log(double);
D }
Line C — The variable is called doubled, not double. Using a name that was never created causes a ReferenceError. It should be console.log(doubled);
Question 2
A for (let i = 1; i <= 12; i++) {
B let answer = i * 7;
C console.log(i + ' x 7 = ' + 7);
D }
Line C — This prints 7 on every repeat because it uses the number 7 instead of the answer variable, which changes with i. It should end with + answer);
Question 3
A for (let i = 1; i <= 5; i--) {
B console.log(i);
C }
Line A — i-- makes i go down (1, 0, -1...) so it never gets past 5 and the loop never ends. To count up it should be i++.
Question 4
A for (let i = 1; i <= 3; i++) {
B console.log(i);
C }
D console.log(i);
Line D — i is local to the loop and only exists inside the curly braces. Using it after the loop causes a ReferenceError. This line should be something that does not use i, like console.log('Done');
Question 5
A let sum = 0;
B for (let i = 1; i <= 5; i++) {
C sum += i;
D console.log(i + ': ' sum);
E }
Line D — There is a + missing between the text ': ' and sum, which is a syntax error. It should be console.log(i + ': ' + sum);

Student with a class code? Join your class →