cancel
Showing results for 
Search instead for 
Did you mean: 
EN
cancel
Showing results for 
Search instead for 
Did you mean: 
jc4d
Expert

Multiple IF statements

Hello,

 

I'm trying to set multiple IF statements depending on a values list set on the Paramaters. If I set only to statements everything works as expected, but when I add more than two statements I get an error.

 

Here is the code:

!!!!!======== MODULE WIDTH ===========
IF WIDTH="600" THEN MOD_WIDTH=0.6

IF WIDTH="900" THEN
	MOD_WIDTH=0.9

ENDIF

!!!!!======== MODULE DEPTH ===========
IF DEPTH="300" THEN MOD_DEPTH=0.3

IF DEPTH="400" THEN
	MOD_DEPTH=0.4

IF DEPTH="500" THEN 
	MOD_DEPTH=0.5

IF DEPTH="600" THEN
	MOD_DEPTH=0.6

ENDIF


RECT2 0,0, MOD_WIDTH, MOD_DEPTH

 

Juan.

1 Solution

Accepted Solutions
Barry Kelly
Moderator

If your IF/THEN is all on one line, you don't need an ENDIF.

If you split it over multiple lines then you do need an ENDIF for every IF/THEN.

 

IF WIDTH="600" THEN MOD_WIDTH=0.6

IF WIDTH="900" THEN
	MOD_WIDTH=0.9
ENDIF

!!!!!======== MODULE DEPTH ===========
IF DEPTH="300" THEN MOD_DEPTH=0.3 !!!don't need ENDIF if single line

IF DEPTH="400" THEN
	MOD_DEPTH=0.4
ENDIF

IF DEPTH="500" THEN 
	MOD_DEPTH=0.5
ENDIF

IF DEPTH="600" THEN
	MOD_DEPTH=0.6
ENDIF


RECT2 0,0, MOD_WIDTH, MOD_DEPTH

 

But for the sake of clean coding I would do them all the same way.

I prefer to split them over multiple lines.

 

Barry.

One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11

Go to post

9 Replies 9
Barry Kelly
Moderator

If your IF/THEN is all on one line, you don't need an ENDIF.

If you split it over multiple lines then you do need an ENDIF for every IF/THEN.

 

IF WIDTH="600" THEN MOD_WIDTH=0.6

IF WIDTH="900" THEN
	MOD_WIDTH=0.9
ENDIF

!!!!!======== MODULE DEPTH ===========
IF DEPTH="300" THEN MOD_DEPTH=0.3 !!!don't need ENDIF if single line

IF DEPTH="400" THEN
	MOD_DEPTH=0.4
ENDIF

IF DEPTH="500" THEN 
	MOD_DEPTH=0.5
ENDIF

IF DEPTH="600" THEN
	MOD_DEPTH=0.6
ENDIF


RECT2 0,0, MOD_WIDTH, MOD_DEPTH

 

But for the sake of clean coding I would do them all the same way.

I prefer to split them over multiple lines.

 

Barry.

One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
Jochen Suehlo
Moderator Emeritus

You did not close the second and third last IF statement with ENDIF

Jochen Suehlo . AC12-29 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de
Lingwisyer
Guru

Unrelated to the question, BUT if your input is set to "Length Type" it is automatically converted to meters in the scripts. So an input value of 300 (mm) is read as 0.3 in the script. Your parameter script would then be

 

VALUES "Depth" 0.3, 0.4, 0.5, 0.6, 0.9

 

In doing this, there would be no need to have all of these statements to convert your "Text Type" into a "Length Type". Unless I guess if you are wanting to include text within the input for what ever reason, or the usage is completely different to what I am thinking.

 

 

Ling.

AC22-29 AUS 3200Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win11 | i9 10850K | 64GB | RX6600 Win11 | R5 2600 | 16GB | GTX1660
jc4d
Expert

Thank you for pointing it out, just noticed and fixed it in VALUES.

jc4d
Expert

Nood question of the day, there is no performance difference between one line IF or split it in multiple lines?

jc4d
Expert

Thank you, that was my problem/doubt.

Barry Kelly
Moderator

No.

I just think it is clearer on multiple lines.

Then you can indent between the IF/ENDIF to make it clear that it is a little group.

Seeing as we have no colour coding of scripts in GDL.

 

Barry.

One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
Lingwisyer
Guru

I would also avoid scripting in ALL CAPS and keep capitalisation to key things such as commands for additional clarity.

AC22-29 AUS 3200Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win11 | i9 10850K | 64GB | RX6600 Win11 | R5 2600 | 16GB | GTX1660
Peter Baksa
Graphisoft
Graphisoft

Generally users aren't affected by GDL code performance. Executing the script is much faster than showing its result model/drawing.

SEO operations (groups, cuts), large file I/O can start to be problematic.

Péter Baksa
Software Engineer, Library
Graphisoft SE, Budapest

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!