💻
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:
let i = 1— start at 1i <= 5— repeat while i is less than or equal to 5i++— after each step increase i by 1
javascript
💬
while repeats the block as long as the condition is true.
Як читати цикл for:
let i = 1— починаємо з 1i <= 5— повторюємо поки i менше або рівне 5i++— після кожного кроку збільшуємо i на 1
break і continue — вийти або пропустити
break — зупиняє цикл повністю і виходить з нього.
continue — пропускає поточну ітерацію і переходить до наступної.
javascript
💬
break повністю виходить з циклу. continue пропускає решту тіла поточної ітерації і переходить до наступної.
javascript
💬
while повторює блок, поки умова true.