Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

switch statement in GDL

Anonymous
Not applicable
Hi all,

Is there a smart way to make a switch statement ala

switch var {
case 'example': DO SOMETHING;
case 'anotherex': DO SOME OTHER THING;
}

As far as I can see, I can't even do an ELSIF, so for now, I am left with the choice between potentially very deep nested IF-trees or letting control do the check for all possible values, no matter what.

I am a bit confused that it seems switching statements (or at least elseif) does not exist, as this is a a pretty essential feature for any programming language...
Wikipedia on switch statements

- Jeppe
5 REPLIES 5
Rob
Graphisoft
Graphisoft
jeppe,

there is no switch or elsif like GDL command. I suppose you will have to get used to it mate. GDL is geometry oriented language and very specific to just one application so I do not think it should keep up with other broad scope programming languages in that part.
::rk
Frank Beister
Moderator
IF THEN ELSE ENDIF

That's it.
bim author since 1994 | bim manager since 2018 | author of selfGDL.de | openGDL | skewed archicad user hall of fame | author of bim-all-doors.gsm
TomWaltz
Participant
GDL is a pretty simple language. I've long hoped for it to at least get SOME modern abilities (like switch/case commands, autocompletion, and a real IDE)
Tom Waltz
Anonymous
Not applicable
TomWaltz wrote:
GDL is a pretty simple language. I've long hoped for it to at least get SOME modern abilities (like switch/case commands, autocompletion, and a real IDE)
(and ability for one GDL object to place other independent GDL objects)
(and a few standard functions on "Right click" that you could use in your object, like place new hotspots on a hotline to split it up, change attributes on hotline, then we would have ability to make more flexible but easy objects without advanced API hacking, I'm already having an idea that wouldn't be that hard to implement)
Anonymous
Not applicable
To simulate the switch/case function I sometimes use something like:
IF something GOTO 10
IF something_else GOTO 20
IF another_thing GOTO 30

10: DO make_hay
!...and so on
WHILE the_sun = shine
GOTO 1000

20: REPEAT the_impossible
!...and so on
UNTIL pigs = fly
GOTO 1000

30: !__enough already!

1000: !__done with cases...

This is functionally not much different than a simple series of IF THEN ENDIF statements but it is sometimes easier to read and maintain. It does avoid reading any subsequent conditions after it finds a match which is either a bug or a feature depending on the circumstances.