Beginner
+35 XP

👋 Start learning JavaScript right now — for free!

💻

For Loop

Repeat actions many times without duplicating code

🔄

Loop = assembly line

Imagine a factory assembly line that performs the same action 100 times. A for loop is the same: you specify how many times to repeat an action, and the program does it automatically.

javascript
💬

for (start; condition; step) — that's the loop structure.

How to read a for loop:

  1. let i = 1 — start at 1
  2. i <= 5 — repeat while i is less than or equal to 5
  3. i++ — after each step increase i by 1
javascript
💬

while repeats the block as long as the condition is true.

Як читати цикл for:

  1. let i = 1 — починаємо з 1
  2. i <= 5 — повторюємо поки i менше або рівне 5
  3. i++ — після кожного кроку збільшуємо i на 1

break і continue — вийти або пропустити

break — зупиняє цикл повністю і виходить з нього.
continue — пропускає поточну ітерацію і переходить до наступної.

javascript
💬

break повністю виходить з циклу. continue пропускає решту тіла поточної ітерації і переходить до наступної.

javascript
💬

while повторює блок, поки умова true.

Comments

Log In or Start to leave a comment.