+ 5
What is the output of this code? for(var x =0; x==x; x++) { if(x > 5 && x < 8) { document.write(x); break;} }
5 Réponses
+ 3
It's a challenge question, I wanted to find out how the answer actually came to 6.
+ 3
I have seen the answer. I just need to know the 'how' part. Regards
+ 3
Makes loads of sense!! Great thanks there!
+ 2
You can run it in your code playground
+ 1
david chongo lol i thought you were lazy to run the code.
Then the explanation:
This is basically and infinite loop (see the 2nd statement. It is always true. So the loop will continue without breaking).
While it was running it increases x by 1. And inside the loop there is an if condition which checks whether x is in the range of 6 and 7.
During.the loop x eventually become 6. So the statements inside the loop start to work. It 1st write 6 inside the body and then break the infinte loop.
Hope you get it.