Skip to content
Advertisement

Why does it ignore my continue in the for-loop? [closed]

JavaScript

Hello I’m new here and would like to know, why my for-loop doesn’t react to the continue. It goes into the else branch. But just ignores the continue.

Advertisement

Answer

I suspect you have it backwards: continue is being executed when it shouldn’t be.

You need to use elif for your sequence of conditions. Your else: block is only associated with the last if condition. So if the key is K_LEFT it will go into the else: block and continue, instead of executing the rest of the loop.

JavaScript

This way, the else: block will be executed only when none of the if conditions succeeded.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement