Hilmas User's Guide
Back Language Basics Next

Control structures.

Control statements allow a program to decide what to do according to the content of certain variables. Every language must have these instructions and every control statement resembles in every language. In Hilmas (and in every modern language) control statements allow to do structured programming, that is, allows to divide program in logical blocks, nested if necessary, avoiding use of harmful GO TO.
Every control statement can be nested with other control statements of the same type or different; nesting level is limited to 20 for statement of the same type. If more is needed, program blocks must be separated in internal subroutines.

There isn't a GO TO instruction in Hilmas; if your program follows directives of structured programming you don't need any GO TO.
But if you want to program "quick and dirty" you can use native assembler instruction B (Branch) to pass control unconditionally to a specified label; for example:

   B MYJUMP
. . . . . . .
MYJUMP CONTINUE

 

IF statement.

IF the logical condition is verified, THEN the following statements (none, one or more) are executed, ELSE are performed the statements between ELSE and ENDIF. ELSE branch is optional, ENDIF is mandatory.

IF (var1,comp1,var2),op,(var3,comp2,var4)... [THEN]
   <statements>
[ELSE]
   <statements>
ENDIF

The use is similar to all IF statement in every programming language; rather, there are some limits in the way to write the logical condition.
There constraints are common to all statements that use logical expressions: no operator precedence, only one level of parentheses, etc.
See preceding page for details.

 

SELECT WHEN statement.

If a great number of IF statements should be nested to obtain the wanted flow, can be useful SELECT statement, that is borrowed from REXX. In short:

SELECT
WHEN
(var1,comp1,var2),op,(var3,comp2,var4)...

      <statements>
[WHEN (var5,comp3,var6),op,(var7,comp4,var8)...
      <statements>]

[OTHERW]

      <statements>

ENDSEL

Statements following WHEN are executed if condition is true, in this case program next continues after ENDSEL statement; WHEN block can be repeated all the times you want with all the needed conditions. If none of the specified conditions is verified, control passes to block defined by OTHERW (i.e. otherwise), if present; if OTHERW is not present, control exit to ENDSEL.

Usually, only one WHEN block is executed, the first, even when more conditions should satisfied; if you want override this behaviour you can end one, more or all WHEN block with a NOBREAK, in this way control is transferred to the next WHEN condition. With NOBREAK, behaviour is similar to "switch-case" statement of C language.
With BREAK instead, block execution is in advance interrupted and control exit to ENDSEL.

 

WHILE statement.

This and the following control statements are looping control statement, that is a block of instructions is executed more and more times as long as condition occurs that allow to exit.

Here, condition is specified in WHILE statement and loop is performed if condition is true.

WHILE (var1,comp1,var2),op,(var3,comp2,var4)... [DO]
      <statements>
ENDWHILE

If you want to exit in advance from a WHILE loop, use LEAVEW statement.

If you want to short the loop, that is to start a new iteration before the normal end delimited by ENDWHILE statement, use ITERATEW statement.

 

REPEAT UNTIL statement.

In this looping control statement, condition is specified in UNTIL statement that close the loop, and loop is performed only if condition is false.

REPEAT
      <statements>
UNTIL (var1,comp1,var2),op,(var3,comp2,var4)...

Instead of WHILE, that can be never performed, REPEAT loop is performed at least one time.

If you want to exit in advance from a REPEAT loop, use LEAVER statement.

If you want to short the loop, that is to start a new iteration before the normal end , use ITERATER statement.

 

FOR statement.

In FOR looping control statement (borrowed from BASIC), loop is done a determined number of times, controlled by an integer counter.

FOR counter,start,end[,STEP=integer]
     <statements>
NEXT

counter is an integer variable: the first time is initialized with start value and every time is incremented by 1 until exceed end value.

Step (by default = 1) can be changed with STEP= parameter; if start > end STEP= must be specified and must be a negative number.

If you want to exit in advance from a FOR loop, use LEAVEF statement.

If you want to short the loop, that is to start a new iteration before the normal end delimited by NEXT statement, use ITERATEF statement.

 


Back Start Next
Expressions Top Subroutines