Ask Question
23 October, 05:32

How many times will the following loop execute?

var num = 10;

while (num > 0)

{

document. getElementById ("outputDiv"). innerHTML = document. getElementById ("outputDiv"). innerHTML + " "+num + "

";

}

1

10

0

infinite times

+1
Answers (1)
  1. 23 October, 08:26
    0
    The correct answer is Infinite times.

    Explanation:

    Here var num=10;

    while (num>0)

    {

    }

    10>0 condition is true

    but no increment or decrement of num. That is why num >0 is always TRUE So the loop will run for infinite times and execute the statement inside of loop every time. This loop will never terminate.

    The syntax of while loop

    while (condition checking)

    {

    statement

    increment/decrement;

    }

    In the given code no increment / decrement so output is infinite times.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “How many times will the following loop execute? var num = 10; while (num > 0) { document. getElementById ("outputDiv"). innerHTML = ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers