-
Notifications
You must be signed in to change notification settings - Fork 0
For Each Loops : JS
Marie-Louise edited this page Jan 31, 2019
·
10 revisions
Contains three expressions separated by ; inside the parentheses (``):
-
an initialisation starts the loop and can also be used to declare the iterator variable
var i = 0. -
a stopping condition is the condition that the iterator variable is evaluated against— if the condition evaluates to true the code block will run, and if it evaluates to false the code will stop.
-
an iteration statement is used to update the iterator variable on each loop.
for (let counter = 0; counter < 4; counter++) { console.log(counter); }
for (let counter = 5; counter < 11; counter++) { console.log(counter); }
The loop below loops from 0 to 3. Edit it to loop backwards from 3 to 0
for (let counter = 3; counter >= 0; counter--){
console.log(counter);
}