New course! Every coder should learn Generative AI!
Try a free lesson0
what is wrong in the code????
fun main() { var isDownloaded = false while(!isDownloaded){ println("File is downloaded") } }
3 Answers
+ 6
That '!' means NOT.
So this code says:
while (not isDownloaded)
same as
while (isDownloaded = false)
print 'File is downloaded'
And isDownloaded is set to false!
And it will never changed in the while loop. So it's a never ending loop.
+ 4
It's true that it would cause infinite loop, but if you're running the code in Code Playground, the runtime limit will prevent such code from running infinitely (and exhaust the system)
0
yes I know but why the compiler does not generate infinity, the problem is in the code or in the compiler