what is wrong in the code???? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is wrong in the code????

fun main() { var isDownloaded = false while(!isDownloaded){ println("File is downloaded") } }

25th Dec 2021, 9:03 PM
время Ч
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.
25th Dec 2021, 9:29 PM
Coding Cat
Coding Cat - avatar
+ 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)
26th Dec 2021, 1:13 AM
Ipang
0
yes I know but why the compiler does not generate infinity, the problem is in the code or in the compiler
25th Dec 2021, 9:37 PM
время Ч