𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗟𝗼𝗼𝗽𝘀: 𝗙𝗼𝗿, 𝗪𝗵𝗶𝗹𝗲, 𝗮𝗻𝗱 𝗗𝗼-𝗪𝗵𝗶𝗹𝗲
Loops repeat tasks for you.
The For Loop uses three parts:
- Start: Set your variable.
- Condition: The loop runs while this is true.
- Step: Change the variable after each turn.
You do not need all three parts. Skip the start if you set the variable before the loop. Skip the step if you change the variable inside the loop.
Be careful with the condition. If you skip it, your browser crashes unless you use a break.
The While Loop repeats code as long as a condition stays true.
The Do-While Loop is different. It runs the code first. It checks the condition last. This means the code runs at least once.
Source: https://www.w3schools.com/js/js_loop_while.asp Optional learning community: https://t.me/GyaanSetuAi