If we want a group of statement to be executed at last once then we can use the do....while loop. This is possible because the condition of the do...while loop is placed at the end of the loop.
Now here we create a web page named dowhileloopuse.html which shows the use of the do...while loop.
####Showing the code for the dowhileloopuse.html file######
<!DOCTYPE html>
<html>
<head>
<title>The Use of do..while Loop</title>
</head>
<body background="images.jpg" text="#ff34AS">
<h1>The Use of The do..while loop in the JavaScript</h1>
<SCRIPT type="text/javascript">
var t_Distance=0,fare=0;
do{
document.write("Rs."+fare+"for"+t_Distance+"KM distance<br/>");
document.write("<hr/>");
fare=fare+5;
t_Distance=t_Distance+2;
}
while(t_Distance<=10);
</SCRIPT>
</body>
</html>
After assigning values to the t_Distance and fare variables the group of statement inside the do..while loop is executed. After executing the group of statement the condition is evaluated. Note that in the first iteration the condition is true because the t_Distance variable has the value 2. The do..while loop executes repeatedly until the condition of the loop is false that is the value of the t_Distance variable becomes more than or equal to 10.
Now here we create a web page named dowhileloopuse.html which shows the use of the do...while loop.
####Showing the code for the dowhileloopuse.html file######
<!DOCTYPE html>
<html>
<head>
<title>The Use of do..while Loop</title>
</head>
<body background="images.jpg" text="#ff34AS">
<h1>The Use of The do..while loop in the JavaScript</h1>
<SCRIPT type="text/javascript">
var t_Distance=0,fare=0;
do{
document.write("Rs."+fare+"for"+t_Distance+"KM distance<br/>");
document.write("<hr/>");
fare=fare+5;
t_Distance=t_Distance+2;
}
while(t_Distance<=10);
</SCRIPT>
</body>
</html>
After assigning values to the t_Distance and fare variables the group of statement inside the do..while loop is executed. After executing the group of statement the condition is evaluated. Note that in the first iteration the condition is true because the t_Distance variable has the value 2. The do..while loop executes repeatedly until the condition of the loop is false that is the value of the t_Distance variable becomes more than or equal to 10.
No comments:
Post a Comment