0% found this document useful (0 votes)
11 views9 pages

Loops in Javascript

The document discusses different types of loops in Javascript including for, while, and do-while loops. It provides the syntax for each loop and describes how to use continue and break statements to control loop execution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views9 pages

Loops in Javascript

The document discusses different types of loops in Javascript including for, while, and do-while loops. It provides the syntax for each loop and describes how to use continue and break statements to control loop execution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Loops in

Javascript
Javascript for loop

In programming, loops are used to repeat a block of code. For example, if


you want to show a message 100 times, then you can use a loop.
The syntax of the for loop is:

for (initialExpression; condition; updateExpression){


// for loop body
}
for loop flowchart
Javascript while loop

The syntax of the while loop is:

while (condition) {
// body of loop
}
while loop flowchart
for vs while loop

A for loop is usually used when the number of iterations is known. And while
and do...while loops are usually used when the number of iterations are
unknown.
Javascript do-while loop

The syntax of do...while loop is:

do {
// body of loop
} while(condition)

Note: do...while loop is similar to the while loop. The only difference is that in do…
while loop, the body of loop is executed at least once.
do-while loop flowchart
continue and break

The break statement is used to terminate the loop immediately when it is


encountered.

The continue statement is used to skip the current iteration of the loop and the
control flow of the program goes to the next iteration.

You might also like