Catalog / Modula-2 Cheatsheet
Modula-2 Cheatsheet
A concise cheat sheet for the Modula-2 programming language, covering syntax, data types, control structures, and module structure.
Basic Syntax and Structure
Program 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.
|
Data Types
|
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., |
Variable Declarations
Variables must be declared before use. Use
|
Constants are declared using the
|
Control Structures
Conditional Statements
|
Example:
|
Looping Statements
|
Example:
|
|
Example:
|
|
Example:
|
CASE Statement
|
Example:
|
Modules and Procedures
Module Structure
A module consists of a definition part and an implementation part. Definition Module:
Implementation Module:
|
Importing modules:
|
Procedure Declaration
Procedure declaration syntax: |
|
Example: |
|
Function Procedures
Procedures can also act as functions, returning a value.
|
Advanced Features
Pointers
Pointers are used to store the address of a variable.
|
|
Arrays
Array declaration: |
|
Accessing array elements: |
|
Records
Records are used to group related data items.
|