¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita+ 5
The result of the code is 9 but I don't understand why. Please someone should help explain to me why?
var count = 6, sum = 0; while(count>0) { sum+=3; count-=1; if(count==3) { count = 0; } } document.write(sum);
7 Respuestas
+ 5
Thanks ~ swim ~, that explanation was clear and precise
+ 3
Count = 6, 5, 4 Sum = 3, 6, 9 😊
+ 2
Ez, to those who still don't understand, it's looping count -= 1 simply by subtracting 1 and setting it as the new variable value, until it reaches 3 from 6... Which is three times. In those three times the code is also adding 3 to sum that was originally 0... And 0 plus 3 three times makes 9. Hope that helps.
+ 1
👍
+ 1
👍
- 1
🙂
- 1
Tq you are clarify my doubt