JAVA SCRIPT
June 3, 2026 2 min read

JavaScript Loops: For, While, Do-While | Nested Loops Explained

HS
HEMANT SINGH
Technical Writer & Educator

Repeatation of any statement is called a loop.

 

There are three types of loop.

  1. For loop
  2. while loop
  3. do while loop

 

for loop

It is called a fixed loop, where initialisation, condition and increment/decrement write together.

 

syntax:

for(start; end; step){
	statements to be repeat
}
statement to not repeat

 

while loop

it is called entry control loop, where we check condition first then execute.

 

syntax

 

start;
while(end){
	statements to be repeat
	step;
}

do while loop

it is called exit control loop, where we check the condition at last.

do while loop run atleast one time either condition true or false.

 

syntax:

start;
do{
	statement to be repeat
	step;
}
while(end);

 

Nested loop

Loop inside a loop is called nested loop, any loop can be write as nested loop.

 

syntax

for(start; end; step){
	inside part of outer loop
	for(start; end; step){
		// inside part of inner loop
	}
}