Loops

In Javascript, there are a few different types of loops that can be used to perform a set of instructions for a finite number of times. This blog will review some of them and what they are typically used for.
The For loop or For Statement will run until a specified conditon is met. It consists of an initialization statement, condition statement and an iteration statement.
for(initialization; condition; iteration){
statement
}
Initialization: This part of the loop starts the counter(s) or declares the iterable variable.
Condition: This is where the loop evaluate while true. The loop stops once the condition is false. If there is no condition statement, the condition will always be true.
Iteration Statement: This statement is responsible for updating the iterator every time the loop executes.
for(let i = 1; i <= 3; i++){
console.log(i)
}//output: 1, 2, 3
The While Loop or statement is sort of similar to the for loop. It will create a loop that will execute as long as condition is true.
while(condition){
statement
}let i = 1
while(1 <= 3){
console.log(i)
i++
}//output: 1, 2, 3
The Do-While Loop or statement is one where a block of code runs while the condition is true. In this case, the loop will always execute at least once. The loop will stop once the condition is false.
do{
statement
}while(condition)i = 1
do{
console.log(i)
i++;
}while (i <= 3);
// output: 1, 2, 3