Go to Triangle Digital Support Home Page TDS2020F TECHNICAL MANUAL
Programming
Control structures
Live website search
Enter key words
 

CONTROL STRUCTURES

DEFINITIONS

 

n2 n1 DO  .   LOOP

Loop n2-n1 times, maximum 65536 times but will always loop at least once. Index starts with n1 and increments at LOOP each time around.

n2 n1 DO  .   n3 +LOOP

Similar but index increases by n3 each time giving a maximum number of loops of INT((n2-n1)/n3)

BEGIN  .  f UNTIL

Loops until f is true (non-zero).

BEGIN  .  AGAIN

Indefinite loop used only as top level of hierarchy of software, such as the word entered at power-up or the word executed by another task.

BEGIN  .  f WHILE  .  REPEAT

Most general of loops. Circulates around BEGIN and REPEAT until f is false, when execution jumps from WHILE to after REPEAT .

n IF  .   ELSE  .  THEN

Executes code from IF to ELSE if n is true, otherwise executes the code from ELSE to THEN .

RECURSE

Execute the current word definition, occasionally preferable to loops.

CASE w OF  .   ENDOF

Executes one of many possible sections of

     x OF   .  ENDOF

code. nx represents possible value(s)

     y OF   .  ENDOF

of n. cond is any conditional such as

     . (more if needed) .

>  = or < . See example in WORD LIST, page 380.

 DUP nx cond IFCASE . ENDOF

 

 . (default if none of above) .

 

ENDCASE

 

OVERVIEW

Basic control flow patterns

Basic control flow patterns


Additional basic control flow patterns

Additional basic control flow patterns


Extended control flow patterns

Extended control flow patterns


The three diagrams illustrate control flow. Note the multiple exits from loops in the last two cases. See USING FLASH CHIPS, page 281, for an example. Even these structures exist in equivalent assembler versions.

Go to Triangle Digital Support Home Page Go to top   Next page