Modula 2 Quick Syntax Reference

Beginners Version

Program Structure

MODULE ModuleName;

    FROM IO IMPORT WrStr, WrLn;   import general procedures

    CONST PI = 3.1416;           constante-declarations

    VAR aNumber: CARDINAL;        variabele-declarations

BEGIN
        ...                      statements
END ModuleName.
 

Single Types

assignment: variable := value;
variables defined in the module (not in a procedure) are initialised with a 0.

Structured Types

Procedures

PROCEDURE MyFunction(inputVariable1, inputVariable2: CARDINAL; inputVariable3: WeekdayRc): BOOLEAN;
    VAR result: BOOLEAN;   variabele-declarations
BEGIN
    ...                   statements
    RETURN result;
END MyFunction;

Operators

Use round brackets (haakjes) to indicate evaluation priorities
  eg: IF x MOD 3 = 0 THEN   gives an error (the = operation is evaluated before the MOD)
  this should be: IF (x MOD 3) = 0 THEN

Control Statements

IF (a > 5) OR (b > 6) THEN      condition
    ...                       statements
ELSE                       optional
    ...                       statements
END;
 

WHILE NOT (i > 10) DO       condition
    statements...
END;
 

REPEAT
    statements...
UNTIL (i = 10);

FOR  i := 10 TO 0 BY -1 DO     By clause is optional
    statements...
END;

Library RealMath (mathematical functions on reals)

Procedures (library IO) Take these to when using black window

Procedures (library Graph)

Colours are defined as numbers from 0 to 15, or use the constants _clrBLACK, _clrBLUE, _clrGREEN, _clrCYAN, _clrRED, ...
Coordinates and colours are cardinals.