Modula-2 programs are organized into modules. A main module is the entry point.
MODULE MainModule;
(* Declarations *)
BEGIN
(* Statements *)
END MainModule.
A concise cheat sheet for the Modula-2 programming language, covering syntax, data types, control structures, and module structure.
Modula-2 programs are organized into modules. A main module is the entry point.
|
Comments are enclosed in
|
Identifiers are case-sensitive and must start with a letter.
|
|
Whole numbers (e.g., |
|
Floating-point numbers (e.g., |
|
Logical values: |
|
Single characters (e.g., |
|
Non-negative integers (e.g., |
|
Array of characters (e.g., |
Variables must be declared before use. Use
|
Constants are declared using the
|
|
Example:
|
|
Example:
|
|
Example:
|
|
Example:
|
|
Example:
|
A module consists of a definition part and an implementation part. Definition Module:
Implementation Module:
|
Importing modules:
|
Procedure declaration syntax: |
|
Example: |
|
Procedures can also act as functions, returning a value.
|
Pointers are used to store the address of a variable.
|
|
Array declaration: |
|
Accessing array elements: |
|
Records are used to group related data items.
|