GAME DEV 2026 · JAVASCRIPT FUNDAMENTALS

t1a08 — Loops by Innes

A loop repeats code. Loops are useful when you need to do something many times without writing the same instructions repeatedly.

Reference: JavaScript For Loops

1. Basic for loop

for (let myLoop = 0; myLoop < myMax; myLoop++) {
  // code runs once for each loop
}

A for loop has a starting value, a condition, and an update. This example starts at zero and stops before myMax.

2. Try the original loop examples

Loop output

Choose an example to run the loop.

3. More loop examples

While loop

let myCount = 0;
while (myCount < 3) {
  console.log(myCount);
  myCount++;
}

A while loop repeats as long as its condition remains true. Make sure something changes the condition, or the loop may never stop.

Array loop

const myGames = ['Minecraft', 'Roblox', 'Celeste'];
for (const myGame of myGames) {
  console.log(myGame);
}

A for...of loop visits each item in an iterable, such as an array.

Challenge

Make a loop that prints the numbers from 1 to 20, but writes “Fizz” for multiples of 3 and “Buzz” for multiples of 5. What should it print for 15?