DEV Community

swetha palani
swetha palani

Posted on

LOOPING IN JS

A loop is a programming tool that is used to repeat a set of instructions.

THERE ARE 3TYPES OF LOOPS:

for Iterates over values and expressions
while Iterates over a condition
do...while Iterates over a condition

  1. FOR LOOP:

For Loops can execute a block of code a number of times.
For Loops are fundamental for tasks like performing an action multiple times.

SYNATX:

for (initialization; condition; increment/decrement) {
    // Code to execute
}
Enter fullscreen mode Exit fullscreen mode

2.WHILE LOOP:

Some loops execute a block of code as long as a specified condition is true.

SYNTAX:

 while (condition) {
  // code block to be executed
}
Enter fullscreen mode Exit fullscreen mode

3.DO WHILE LOOP:

while is similar to while loop except it execute the code block at least before checking the condition.

SYNTAX:

do {
    // Code to execute
} while (condition);

Enter fullscreen mode Exit fullscreen mode

Top comments (0)