JavaScript Loop : Do-While Loop in JavaScript (Iterative Statement)

February 1, 2025 No Comments » Hits : 392





JavaScript Loop : Do-While Loop in JavaScript (Iterative Statement)

Note :

  • It is Exit Controlled Loop.
  • Initialization , Incrementation and Condition steps are on different Line.
  • It is also called Bottom Tested [i.e Condition is tested at bottom and Body has to execute at least once ]

Do-While Loop Syntax :

initialization;
do
{
--------------
--------------
--------------
--------------
incrementation;
}while(condition);

Live Example :

<html>
<body>
<script type="text/javascript">
i=0;
do
{
document.write("The number is " + i);
document.write("<br />");
i++;
}while(i<=5);
</script>
</body>
</html>

Output :

The number is 0
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5

Semicolon is optional after JavaScript Statement

Incoming search terms: