Javascript - while Loops
Code Life
By Pierre Marsaa
Repeat While Something is True
A for loop is perfect when you know how many turns you need. But sometimes you only know when to stop: attack until the opponent is KO, train until the level is high enough... That's the job of while.
↗️
Loading editor...
↶
↷
The loop checks wildHP > 0 before each turn. As long as it is true, the block runs. As soon as it is false, JavaScript jumps to the code after the loop.
Verify