My question is not in relation to how to write code correctly, but why does Nim playground always crash when this code is executed? Does the snippet above result in some kind of an infinite/impossible loop that the playground compiler doesn't know how to handle?
This is the state of affairs before the code is executed: .. image:: https://i.imgur.com/nvzuGlQ.png
and then immediately after the code's run:
https://i.imgur.com/EwvD3iw.png
Thanks for all your explanations and efforts,
Yes, you have an infinite loop here because i is always smaller than sum :
while i < sum:
inc i, 1
inc sum, i
echo "i:" & $i & " sum:" & $sum # you may add this to see it yourself.
So, It never finishes looping and it can not send a response in time.
important that you understand the differences between "compile-time" and "run-time".
Unfortunately that has become harder for beginners in the last years.
It has become common for beginners to ALWAYS type
nim r mycode.nim
or
nim c -r mycode.nim
I have seen even people who always compile in release mode with -d:release.
That is fine when all works, but in case of problems it is better to split the compile and run phase with
nim c mycode.nim
./mycode
But I think the question was more about the Nim playground, and there is only a "Run" button provided which makes it harder to see the difference of compile time errors or runtime failures.