For loop
What is a for
loop?
A loop allows you to repeat an action based on some condition, similar to an if statement
. In the prior lesson you met the while
loop. The for loop is
similar…
Let’s break it down
For loops can make it a little easier to avoid infinite loops.
So…
let x = 100;
- Before the loop runs
x > 10;
- Condition to check BEFORE each cycle. if true, run the cycle
x--
- AFTER each cycle run this. In this case decrement by 1.