Modula-2 Reference Beginners Version Single Types * CARDINAL * INTEGER * CHAR: characterconstant: 'a' * REAL * BOOLEAN: values TRUE & FALSE operators NOT, AND, OR Structured Types * ARRAY o variable declaration: VAR array1: ARRAY [1..20] OF CARDINAL; o element of array: array1[2] := 1; o special array: string (ARRAY OF CHARs) + assignment: str := "bla"; o multidimensional array : + VAR matrix10by20: ARRAY [1..10] OF ARRAY[1..20] OF CARDINAL; + identical declaration: VAR matrix10by20: ARRAY [1..10], [1..20] OF CARDINAL; + use: matrix10by20[5, 15] := 7; or matrix10by20[5][15] := 7; * RECORD o declaration: + VAR jan : RECORD + name, firstName: ARRAY[1..35] OF CHAR; + length: CARDINAL; + END; o use: jan.name := "Lemeire"; jan.firstName := "Jan"; Operators Operator Explanation NOT, AND, OR logical operators =, # equals, different <, >, >=, <= relational operators 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; Procedures * WrLn; skip to next line * cardinalVariable := RdCard(); read cardinal * WrCard(cardinalVariable, spaces); write cardinal * readVariable := RdInt(); * WrInt(intVariable, spaces); * RdStr(stringVariable); read string (variabele tussen de haakjes!!) * WrStr(stringVariable); write string to output * charVariable := RdChar(); !! 2 ENTER-tokens stay in input buffer, are read in the next time with a RdChar o RdLn; use this after RdChar to read the rest of the input and the ENTER-tokens * WrChar(charVariable); * realVariable := RdReal(); read real from user input * WrReal(realVariable, precision, spaces); write real to output (precision: number of digits) * booleanVariable := RdBool(); ty pe "TRUE" and "FALSE" * WrBool(booleanVariable, spaces);