In this tutorial, we will learn about Looping Statements in JavaScript We use Looping Statement to run a piece of code multiple time without writing it again and again. Suppose we want to write 1 to 100 on-screen we can do this easily with the help of loop.
Page Contents
JavaScript provides us with four kinds of Looping Statements we will learn about these and we will check the example of every Looping Statement. These statements are as follow:
- for loop
- while loop
- do-while loop
Now we will check each statement in detail with example.
for loop:
We use for a loop when we want to run a piece of code for a fixed number of time.
<script>
for (i=1; i<=10; i++)
{
document.write(i + " ")
}
</script>
while loop:
we use this statement when we do not know how much time loop will run but we only know about the condition.
<script>
var num=1;
while (num<=10)
{
document.write(num + " ");
num++;
}
</script>
do-while loop:
This looping statement is the same as while loop expects it will run once even if the condition is false.
<script>
var num=1;
do{
document.write(num + " ");
num++;
}while (i<=10);
</script>

Parvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​