Starlit Daily

📚 › JavaScript: make pages do things

6. Loops: for and while

इस लेख का अनुवाद अपने आप होगा। अभी अंग्रेज़ी में दिखाया जा रहा है।

A for loop repeats code. In for (let i = 1; i <= 5; i++) the variable i starts at 1, the loop runs while i is at most 5, and i increases by one each round.

A while loop repeats while its condition stays true. Make sure something changes, or the loop never ends.

उदाहरण देखें

for (let i = 1; i <= 3; i++) {
  console.log("Round " + i);
}

✍️ अब आपकी बारी

Print the numbers 1 to 5, one per line, using a for loop.

← कोर्स पर वापस