A repeating lap around a track, with a counter ticking up (or down) once per lap until it crosses the finish line.
A for loop repeats a block of code a set number of times, counting with a variable you control: a starting point, a condition to keep going, and a step to move the counter each lap.
for (let i = start; i <= end; i++) {
...
}for (let i = 1; i <= 3; i++) {
console.log(`Lap ${i}`);
}i starts at 1. Each lap: is i <= 3? If yes, run the body (print), then i++ bumps i up by one. i goes 1, 2, 3 - three laps - then 4 <= 3 is false, so the loop stops.
for (let i = 5; i >= 1; i--) {
console.log(i);
}Loops can count DOWN too - i-- lowers i by one each lap, counting 5, 4, 3, 2, 1 until i >= 1 becomes false.
In the app this lesson continues with the animated explanation, spoken aloud, and then the practice: Print "Star 1" through "Star 5", one per line, using a for loop. The editor runs your child’s real code and checks the result, with their coding buddy reacting to what they wrote.
Try it free