Latest Movie :
Home » » The Do While loop

The Do While loop

{[['']]}

You can consider the do-while loop as a modified version of the while loop. Here, the condition is placed at the end of the loop and hence, the loop is executed at least once.

Ex3:

<script>

var x = 20;

do
{

alert("The number is " + x);
x++;
}
while (x <= 10);
</script>

Ex4:

<script>
var x = 20;
do
{
alert("The number is " + x);
x++;
}
while (x <= 30);
</script>

Assignment

Ex5:

<script>
var num=0;
while (num <= 30)
{
document.write(num+"<br>");
num = num + 3;
}
</script>

1- If the value of variable num is 20, how many times will the following while loop be execute

Ex6:
2- How many times is the while loop executed in the following code?

<script>
var b = 45;
var a = 14;
while (a <= 20)
{
document.write("All is well with me");
b = b + 5;
}
document.write("Once time");
</script>

3- If the condition evaluates to 'false', how many times is the do-while loop executed and why?

Possible Answers

Four times

Infinite times since there is no update statement for variable a inside the while loop.

Once, because the condition is present at the end of the loop.

Share this article :
 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. isophal.com - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger