modula-2 home

  Home  
  Tutorial  
  Win32 API  
  Reference  
  Projects  
 

 

IF Statements

   IfStatement = IF expression THEN StatementSequence
      {ELSIF expression THEN StatementSequence}
      [ELSE StatementSequence] END.

The expressions following the symbols IF and ELSIF are of type BOOLEAN. They are evaluated in the sequence of their occurrence, until one yields the value TRUE. Then its associated statement sequence is executed. If an ELSE clause is present, its associated statement sequence is executed if and only if all Boolean expressions yielded the value FALSE.

Example:

   IF (ch>= "A") & (ch <= "Z") THEN ReadIdentifler
   ELSIF (ch > = "0") & (ch < = "9") THEN ReadNumber
   ELSIF ch = '"' THEN ReadString('"')
   ELSIF ch = "'" THEN ReadString("'")
   ELSE SpecialCharacter
   END


Source:

  • Wirth N: Programming in Modula-2, 3rd ed. Springer Verlag, Berlin, 1985.