because the condition inside the while loop (i < 10) is never updated. To fix this, we need to increment the value of i inside the loop:
var i = 0;
while(i < 10){
println("hello");
i++; // increment i by 1
}
Now, the loop will execute 10 times and print "hello" each time. Therefore, the correct answer is 10.
Question: 3
How many times will the following program print "hello"?
var i = 0;
while(i < 10){
println("hello");
}
JavaScript
10
11
9
This code will loop infinitely
1 answer