What gets printed?
var i=6;
while(i<9)
{
i++;
document.write("i value is"+i+"
");
}
I understand that the result is a loop of
"i value is ____"
"i value is ____"
but I'm not sure what to put for i and how many times it's printed?
u have already declared value of i is 6 and the loop will continue until the value of i is less than 9
iteration 1: i=6 while loop : (6<9) is TRUE i= 7 i value is 7 is printed. iteration 2: while loop : (7<9) is TRUE i= 8 i value is 8 is printed iteration 3: i=8 while loop : (8<9) is TRUE i= 9 i value is 9 is printed iteration 4: i=9 while loop : (9<9) is FALSE Control does no go inside, so nothing is printed. so whats printed is `i value is 7` `i value is 8` `i value is 9`
A great and fantastic thing about programming is that you check quite easily by compiling the code and executing it.
Join our real-time social learning platform and learn together with your friends!