Page 198 - Web Applications (803) Class 12
P. 198
Output of the preceding program is as follows:
The do….while loop
Do-while loop is a variation of the while loop that is available in JavaScript. The main distinction between
the do-while loop and the while loop is that the former evaluates the condition expression following the
execution of the code block. The code block will therefore be run at least once during the do...while loop.
Syntax:
do {
// Statements to be executed - body of loop
} while(condition);
Flow Diagram:
do...while loop body
True Test
Condition
False
Loop
terminates
Example:
<html>
<body text="blue">
<h2>Using do...while loop in JavaScript</h2>
<font color=green>
<script>
var num = 5;
do {
document.write("The Square of "+ num + " is " +(num*num)+"<br> <br>");
num=num+1;
196 Touchpad Web Applications-XII

