+ 2
The loop ans is 12. Need explanation please
k=6 for (var i=0 ; i < k ; i++) { k+=0.5; } alert(i);
10 odpowiedzi
+ 2
Thank you Aleksei Radchenkov
+ 2
Kapama, Joshua,
No problem 👍
And happy learning!
+ 2
David Stevens, please post your question in a new thread.
+ 1
The answer is 12 instead of 9, because every time you add 0.5 to the k, your loop condition is altered, because k changes, so it takes twice as long to go through the loop. That's why the answer is 12...
+ 1
So sorry Aleksei Radchenkov , if the value of k changes everytime you add up 0.5. Wasn't it suppose to be infinite loop then?? How does the loop get stop
+ 1
Kapama, Joshua, Nope.. 'i' variable gets increased by 1 each iteration, while k gets increased by 0.5. So it will just take twice as long, but it won't be infinite...
+ 1
David Stevens You're question is popular just search it in Q&A. Its good to post in a new thread to get answers quickly, it is not adviced to post question in another thread like this.
- 1
Help how does variables wrk
- 1
Im trying to learn coding from complete scratch