Alfaiz Ali
Alfaiz Ali

@heyAlfaiz

9 Tweets Mar 16, 2023
JavaScript Loops Explained ➰
A Thread ↓↓↓
• Loops in JavaScript ➰
The JavaScript loops are used to iterate the piece of code using five different types of loops. It makes the code compact.
• There are five types of loops in JavaScript.
➞ for loop
➞ while loop
➞ do-while loop
➞ for-in loop
➞ for-of loop
• For Loop
The for loop is the most compact form of looping. Includes three important parts:
Initialization - We initialize our counter to a starting value.
Condition - Will test if a given condition is true or not.
Iteration - You can increase or decrease your counter.
Syntax:
for ( initialization; condition; iteration ) {
// statements
}
➞ For loop flowchart with an example:
• While Loop
The purpose of a while loop is to execute a statement or code block repeatedly as long as an expression is true. Once the expression becomes false, the loop terminates.
Syntax:
while (expression) {
// Statement
}
➞ While Loop flowchart with an example:
• For...Of Loop
ES6 introduced a new statement for...of that iterates over an iterable object such as built-in Arrays.
• For...In Loop
The JavaScript for In statement loops through the properties of an Object and Arrays.
• Do-while Loop
The do...while loop statement creates a loop that executes a block until a condition evaluates to false.
Unlike the while loop, the do-while loop always executes the statement at least once before evaluating the expression.
Thanks so much for getting to the end of it! 🙏
Make sure to follow me @imAlfaiz for more such content! 😇

Loading suggestions...