While(true) and while(condition) infinity loop


I know that it is necessary to take action in each cycle
Code with condition will work if add for example hero.wait(0.01);

But why
This code works fine

while (true) {


And this does not work

while (10 > 5) {



@htrnblr I think it has something to do with the way the code is evaluated. The CodeCombat environment is near to the true environment but not quite.

So code that would normally work in javascript if you just ran it in your browser may not work on CodeCombat. This has both advantages and disadvantages. The core of what you need to know works the same though.

Learn what does work with CodeCombat and use those constructs knowing that once you try this in a web browser directly you can use other approaches as well.


It’s specific to the CodeCombat’s environment. If you don’t have actions inside a while loop, then the system think you are in an infinity loop. It was made on purpose because it’s a problem for beginners. But while (true) is processed by the special way.