JeffLearnsReact – 9 – Loops

for loops, which let us loop a block of code a known amount of times. let myArray = [‘one’, ‘two’, ‘three’, ‘four’]; for (let i = 0; i<myArray.length; i++) { console.log(myArray[i]); } let i = 0; is the start condition – loop will start at 0 i is the iterator variable i<myArray.length is the stop […]

for loops, which let us loop a block of code a known amount of times.

let myArray = [‘one’, ‘two’, ‘three’, ‘four’];

for (let i = 0; i<myArray.length; i++) {
console.log(myArray[i]);
}

let i = 0; is the start condition – loop will start at 0
i is the iterator variable
i<myArray.length is the stop condition
i++ is the iterator

Run a for loop backwards:

for (let i = myArray.length – 1; i >= 0; i– {
console.log(myArray[i]);
}

while loops, which let us loop a block of code an unknown amount of times.

while (condition) {
// code will loop until condition is false
}

Powered by WPeMatico