I know that execution timed out means that there is an endless loop but I can’t find where. I’m doing the snail in the well project. Here is my code: function main() { var depth = parseInt(readLine(), 10); var days=0 var x=0 do{ x+7 } while (x<depth){ x-2 days++ } } Thx
3/10/2021 9:29:13 PM
ElizabethM2 Answers
New Answerit's either a while loop, or a do..while: while (cond) {} or: do {} while (cond); the difference is when cond(itional) expression is evaluated ;)
Have you figured out why the infite loop is happening ElizabethM ? As visph has said, your syntax is a bit off. I think the the infinite loop is because you're not incrementing x. I.e. You're adding 7 but not saving that new value to x. So you probably want x = x+7, or you could do x += 7.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message