+5 votes

I want to write an if statement that spans over several lines, how do I do that?

asked Feb 23, 2016 in Engine by Calinou (6,442 points)

1 Answer

+10 votes
Best answer

You can use parentheses around the if statement, or backslashes before the newline (which should work anywhere).

Take this script for example:

func _ready():
    if (2 == 2
        and 3 == 3
        and 4 == 4
        and 5 == 5
        and 6 == 6):
            print("The parenthesis way of putting 'if' statements on multiple lines.")

    if 2 == 2 \
        and 3 == 3 \
        and 4 == 4 \
        and 5 == 5 \
        and 6 == 6:
            print("The backslash way of putting 'if' statements on multiple lines.")
answered Feb 23, 2016 by Calinou (6,442 points)
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.