var x = 0while( x<6 ){x++;}document.write( x )How is the answer of this is 6? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 5

var x = 0while( x<6 ){x++;}document.write( x )How is the answer of this is 6?

12th Jun 2016, 10:49 AM
Pratik Karanjkar
16 Answers
+ 10
The loop works and when it reaches x=5 it gets incremented to 6 it again checks while loop which is false and the current value of x gets printed.... If u wanna c all value put the write method inside the loop.
12th Jun 2016, 3:42 PM
sreeraj thampan
sreeraj thampan - avatar
+ 3
the loop is 6 time executed, in the last time x became 6!
27th Jun 2016, 7:37 PM
Ivan
Ivan - avatar
+ 2
the variable x is incremented to 6 and then further goes up an check the condition, as 6<6 is false so it will jump out of the loop with the final value of x equalize to 6 .
12th Jun 2016, 11:37 AM
Arnav Gaur
Arnav Gaur - avatar
+ 2
x value is overrided until the loop ends. the final value to overrride is 6.
12th Jun 2016, 1:37 PM
meenakshi sundareswar
meenakshi sundareswar - avatar
+ 1
The loop is executed 6 times from 0-5. Until 6 < 6
12th Jun 2016, 11:07 AM
VenomVendor
+ 1
the loop start with x=0 that causes to 6 time.
13th Jun 2016, 12:22 AM
Zuher Yassin Saif Ali
Zuher Yassin Saif Ali - avatar
0
The loop works and when it reaches x=5 it gets incremented to 6 it again checks while loop which is false and the current value of x gets printed
4th Mar 2020, 8:30 AM
MD SHAKIL
MD SHAKIL - avatar
0
The loop's 6 time Execute. when x=5. Check and gets increment 6. then check Again 6<6 loop false. print current value 6
18th Jul 2020, 8:39 PM
MD SHAKIL
MD SHAKIL - avatar
0
6
2nd Dec 2021, 3:22 PM
Md. Rakibul Islam
Md. Rakibul Islam - avatar
0
6
3rd Jun 2022, 10:32 AM
ERICK KIMUTAI KORIR
- 1
answer is 6 because increment occurs after checking the condition
14th Jun 2016, 3:02 AM
Alex Kudin
Alex Kudin - avatar
- 1
The scope of while loop is getting over and after that we are doing document. Write(x) so it will come 6
14th Jun 2016, 6:48 AM
Shikhar Seth
Shikhar Seth - avatar
- 1
6 ok.
30th Jun 2016, 1:48 PM
fuuChong
fuuChong - avatar
- 1
012345
25th Aug 2016, 12:35 AM
sagir
sagir - avatar
- 1
Answer: 6
4th Jun 2020, 12:23 AM
George
- 1
What is the output of this code? var x = 0; while(x<6) { x++; } document.write(x); 6
9th Dec 2020, 5:03 PM
tieflabs
tieflabs - avatar