0 votes

How I define OR in code?

I need write something like this:

if var == 1 or 2 or 3:
   do something()

Thank you for answer.

asked May 4 in Engine by Eidam (175 points)

1 Answer

+2 votes
Best answer

You need to make all of the comparisons:

if var == 1 or var == 2 or var == 3:

For the same conditions, you could also do:

if var >= 1 and var <= 3:

And one more option:

if var in [1, 2, 3]:

All three statements are equivalent.

answered May 4 by kidscancode (17,762 points)
selected May 4 by Eidam

That's exactly what I needed!
Thank you very much

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.