Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
05 ArchiCAD 11 GDL Reference Guide.pdf
Скачиваний:
58
Добавлен:
11.03.2015
Размер:
3.22 Mб
Скачать

CONTROL STATEMENTS

This chapter reviews the GDL commands available for controlling loops and subroutines in scripts and introduces the concept of buffer manipulation designed to store parameter values for further use. It also explains how to use objects as macro calls and how to display calculated expressions on screen.

FLOW CONTROL STATEMENTS

FOR

FOR variable_name = initial_value TO end_value [ STEP step_value ]

First statement of a FOR loop. If the STEP keyword and the step_value are missing, the step is assumed to be 1. A global variable is not allowed as a loop control variable.

Example:

FOR I=1 TO 10 STEP 2 PRINT I

NEXT I

NEXT

NEXT variable_name

Last statement of a FOR loop.

The loop variable varies from the initial_value to the end_value by the step_value increment (or decrement) in each execution of the body of the loop (statements between the FOR and NEXT statements). If the loop variable exceeds the value of the end_value, the program executes the statement following the NEXT statement.

Note: Changing the step_value during the execution of the loop has no effect.

ArchiCAD 11 GDL Reference Guide

209

Control Statements

The two program fragments below are equivalent:

!1st A = B

1:IF C > 0 AND A > D OR C < 0 AND A < D THEN 2 PRINT A

A = A + C GOTO 1

2:

!2nd

FOR A = B TO D STEP C PRINT A

NEXT A

The above example shows that step_value = 0 causes an infinite loop.

Only one NEXT statement is allowed after a FOR statement. You can exit the loop with a GOTO (or IF ... GOTO) statement and to return after leaving, but you cannot enter a loop skipping the FOR statement.

DO

DO

[statment1

statement2

...

statementn]

WHILE condition

The statements between the keywords are executed as long as the condition is true. The condition is checked after each execution of the statements.

WHILE condition DO [statement1 statement2

...

statementn]

ENDWHILE

The statements between the keywords are executed as long as the condition is true. The condition is checked before each execution of the statements.

210

ArchiCAD 11 GDL Reference Guide

Control Statements

REPEAT

[statement1

statement2

...

statementn]

UNTIL condition

The statements between the keywords are executed until the condition becomes true. The condition is checked after each execution of the statements.

Example:

The following four sequences of GDL commands are equivalent:

! 1st

FOR i = 1 TO 5 STEP 1 BRICK 0.5, 0.5, 0.1 ADDZ 0.3

NEXT i ! 2nd i = 1 DO

BRICK 0.5, 0.5, 0.1 ADDZ 0.3

i = i + 1 WHILE i <= 5 ! 3rd

i = 1

WHILE i <= 5 DO

BRICK 0.5, 0.5, 0.1 ADDZ 0.3

i = i + 1 ENDWHILE

! 4th i = 1 REPEAT

BRICK 0.5, 0.5, 0.1 ADDZ 0.3

i = i + 1 UNTIL i > 5

ArchiCAD 11 GDL Reference Guide

211

Control Statements

IF

IF condition THEN label IF condition GOTO label IF condition GOSUB label

Conditional jump statement. If the value of the condition expression is 0, the command has no effect, otherwise execution continues at the label.

Examples:

IF A THEN 28

IF I > J GOTO 200+I*J IF I > 0 GOSUB 9000

IF condition THEN statement [ELSE statement] or

IF condition THEN [statement1 statement2

...

statementn]

[ELSE

statementn+1

statementn2

...

statementn+m] ENDIF

If you write only one command after keywords THEN and/or ELSE in the same row, there is no need for ENDIF. A command after THEN or ELSE in the same row means a definite ENDIF.

If there is a new row after THEN, the successive commands (all of them until the keyword ELSE or ENDIF) will only be executed if the expression in the condition is true (other than zero). Otherwise, the commands following ELSE will be carried out. If the ELSE keyword is absent, the commands after ENDIF will be carried out.

212

ArchiCAD 11 GDL Reference Guide