Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.


4.1 Conditional Block

There are two kinds of conditional block: IF and SELECT. Examples of these blocks are given below as fragments of E code (i.e., the examples are not complete E programs).

  IF x>0
    x:=x+1
    WriteF('Increment: x is now \d\n', x)
  ELSEIF x<0
    x:=x-1
    WriteF('Decrement: x is now \d\n', x)
  ELSE
    WriteF('Zero: x is 0\n')
  ENDIF

In the above IF block, the first part checks if the value of x is greater than zero, and, if it is, x is incremented and the new value is printed (with a message saying it was incremented). The program will then skip the rest of the block, and will execute the statements which follow the ENDIF. If, however, x it is not greater than zero the ELSEIF part is checked, so if x is less than zero it will be decremented and printed, and the rest of the block is skipped. If x is not greater than zero and not less than zero the statements in the ELSE part are executed, so a message saying x is zero is printed. The IF conditional is described in more detail below.

  SELECT x
    CASE 0
      WriteF('x is zero\n')
    CASE 10
      WriteF('x is ten\n')
    CASE -2
      WriteF('x is -2\n')
    DEFAULT
      WriteF('x is not zero, ten or -2\n')
  ENDSELECT

The SELECT block is similar to the IF block--it does different things depending on the value of x. However, x is only checked against specific values, given in the series of CASE statements. If it is not any of these values the DEFAULT part is executed.

There's also a variation on the SELECT block (known as the SELECT..OF block) which matches ranges of values and is quite fast. The two kinds of SELECT block are described in more detail below.


Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.