JavaScript
Repeating with loops
A practical reference with examples you can run.
Introduction
Loops apply the same steps to many values. Start with a small collection so you can follow each iteration. A loop must eventually finish; make sure its condition or sequence moves toward an end.
Syntax & example
for (let number = 1; number <= 5; number++) {
console.log(number);
}Expected output
1 2 3 4 5
Common mistakes
- Using a variable before assigning a value to it.
- Mixing text and numbers without converting deliberately.
- Skipping an empty input or a boundary value when testing.
Practice
Print the numbers from 1 to 5.
main.jsYour ideas, in code.
Loading your editor…
Run your code to see the output here.
Ready to buildUTF-83 lines