Switch statement for George?

A forum dedicated to George scripting questions
Post Reply
User avatar
Jeremy Richard
Posts: 55
Joined: 16 Oct 2021, 01:44
Contact:

Switch statement for George?

Post by Jeremy Richard »

Is there an equivalent to a php switch statement in George?

So instead of this:

Code: Select all

IF colour_choice == 1 || colour_choice == 2 || colour_choice == 3
	...
END
We could do:

Code: Select all

SWITCH (colour_choice) {
    CASE 1
        ...
        BREAK
    CASE 2
        ...
        BREAK
    CASE 3
        ...
        BREAK
}
or:

Code: Select all

SWITCH (colour_choice) {
    CASE 1
        ...
        BREAK
    CASE 2
    CASE 3
        ...
        BREAK
}
User avatar
aAntin
Posts: 37
Joined: 29 Aug 2007, 09:40
Location: France
Contact:

Re: Switch statement for George?

Post by aAntin »

That would be very convenient to avoid the nested IF-ELSE hell, indeed!! 👍🤩

My two cents: using CMP algorithm would be nice to include strings instead of double-equal operator algorithm.

Code: Select all

SWITCH my_string
    CASE "a"
        // ...
        BREAK
    CASE "b"
        // ...
        BREAK
    CASE "c"
        // ...
        BREAK
    DEFAULT
        // ...
        BREAK
END
instead of:

Code: Select all

IF CMP(my_string, "a")
    // ...
ELSE
    IF CMP(my_string, "b")
        // ...
    ELSE
        IF CMP(my_string, "c")
            // ...
        ELSE
            // Default stuff...
        END
    END
END
Thank you! 🙏
Antoine ANTIN
Post Reply