Learn Modula - 10 Code Examples & CST Typing Practice Test
Modula is a procedural programming language and modular systems language designed by Niklaus Wirth. It emphasizes strong typing, modularity, and simplicity, supporting the development of reliable, maintainable software systems.
Learn MODULA with Real Code Examples
Updated Nov 25, 2025
Code Sample Descriptions
Simple Modula-2 Program
# modula2/demo.m2
MODULE Counter;
IMPORT InOut;
BEGIN
FOR i := 1 TO 5 DO
InOut.WriteInt(i, 0);
InOut.WriteLn;
END;
END Counter.
A simple Modula-2 program printing numbers 1 to 5.
Simple Modula-3 Program
# modula3/demo.m3
MODULE Counter;
IMPORT IO;
BEGIN
FOR i := 1 TO 5 DO
IO.Put(i);
IO.PutChar('\n');
END;
END Counter.
A simple Modula-3 program printing numbers 1 to 5.
Modula-2 Fibonacci Sequence
# modula2/fib.m2
MODULE Fibonacci;
IMPORT InOut;
VAR a, b, tmp, i: INTEGER;
BEGIN
a := 0; b := 1;
FOR i := 1 TO 10 DO
InOut.WriteInt(a, 0);
InOut.WriteLn;
tmp := a + b;
a := b;
b := tmp;
END;
END Fibonacci.
Calculates and prints Fibonacci numbers up to 10.
Modula-3 Factorial Program
# modula3/factorial.m3
MODULE Factorial;
IMPORT IO;
VAR n, fact, i: INTEGER;
BEGIN
n := 5; fact := 1;
FOR i := 1 TO n DO
fact := fact * i;
END;
IO.Put(fact);
IO.PutChar('\n');
END Factorial.
Calculates factorial of 5 and prints the result.
Modula-2 Array Sum
# modula2/array_sum.m2
MODULE ArraySum;
IMPORT InOut;
VAR arr: ARRAY 1..5 OF INTEGER := (1,2,3,4,5);
sum, i: INTEGER;
BEGIN
sum := 0;
FOR i := 1 TO 5 DO
sum := sum + arr[i];
END;
InOut.WriteInt(sum,0);
InOut.WriteLn;
END ArraySum.
Sums elements of an integer array.
Modula-3 While Loop Example
# modula3/while_loop.m3
MODULE WhileDemo;
IMPORT IO;
VAR i: INTEGER;
begin
i := 1;
WHILE i <= 5 DO
IO.Put(i);
IO.PutChar('\n');
i := i + 1;
END;
END WhileDemo.
Prints numbers from 1 to 5 using a WHILE loop.
Modula-2 Conditional Example
# modula2/if_example.m2
MODULE EvenOdd;
IMPORT InOut;
VAR n: INTEGER;
BEGIN
n := 7;
IF n MOD 2 = 0 THEN
InOut.WriteString("Even");
ELSE
InOut.WriteString("Odd");
END;
InOut.WriteLn;
END EvenOdd.
Checks if a number is even or odd.
Modula-3 Simple Function
# modula3/double.m3
MODULE DoubleFunc;
IMPORT IO;
PROCEDURE Double(x: INTEGER): INTEGER;
BEGIN
RETURN 2*x;
END Double;
BEGIN
IO.Put(Double(5));
IO.PutChar('\n');
END DoubleFunc.
Defines a function to double a number and prints the result.
Modula-2 Nested Loops
# modula2/mult_table.m2
MODULE Table;
IMPORT InOut;
VAR i,j: INTEGER;
BEGIN
FOR i := 1 TO 5 DO
FOR j := 1 TO 5 DO
InOut.WriteInt(i*j,0);
InOut.WriteString(" ");
END;
InOut.WriteLn;
END;
END Table.
Prints a 5x5 multiplication table.
Modula-3 Record Example
# modula3/record.m3
MODULE PointDemo;
IMPORT IO;
TYPE Point = RECORD x,y: INTEGER END;
VAR p: Point;
BEGIN
p.x := 10; p.y := 20;
IO.Put(p.x);
IO.PutChar(',');
IO.Put(p.y);
IO.PutChar('\n');
END PointDemo.
Defines a record type for a point and prints its coordinates.
Frequently Asked Questions about Modula
What is Modula?
Modula is a procedural programming language and modular systems language designed by Niklaus Wirth. It emphasizes strong typing, modularity, and simplicity, supporting the development of reliable, maintainable software systems.
What are the primary use cases for Modula?
Teaching structured and modular programming. Systems and embedded programming. Research in programming languages and compilers. Developing reliable software with modular architecture. Prototyping software with clear separation of concerns
What are the strengths of Modula?
Encourages clean and maintainable code. Modules enable code reuse and encapsulation. Strong typing reduces runtime errors. Suitable for teaching structured programming concepts. Clear separation of interface and implementation
What are the limitations of Modula?
Not widely adopted in modern industry. Limited libraries and tooling compared to modern languages. Mostly of historical and educational interest. Verbose syntax compared to contemporary languages. Concurrency and modern paradigms not inherently supported
How can I practice Modula typing speed?
CodeSpeedTest offers 10+ real Modula code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.