0
I need an explanation for Javascript (For loop)
k=6; for(var i = 0; i<k; i++) { k+=0.5; } alert (i); // the answer is 12. i cant seem to understand why, with the "0.5" added to the loop. Please i need someone to explain it succintly for me.
7 Respostas
+ 3
If you begin with zero, how many times do you have to repeat adding 0.5 until you get to 6?
+ 2
The for-loop has to be executed first? before what?
+ 2
This might add to your understanding of a for/loop.
https://code.sololearn.com/Ws1oc88oPZWL/#js
+ 1
12 times...
I figured that out but felt its an oddity, Since the "for loop" has to be executed first because before the code block.
+ 1
I meant the statements in the () will be executed first before the statement in {}...
Thanks for your response. I gained more insight in the for loop.
+ 1
You are welcome.
0
Thank you so much for that code explanation... 😎😎😎....
I got that "light-bulb" moment from it... 👌