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.

← العودة إلى الدورة