Modula-2 Array Sum - Modula Typing CST Test
Loading…
Modula-2 Array Sum — Modula Code
Sums elements of an integer array.
# 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.Modula Language Guide
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.
Primary Use Cases
- ▸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
Notable Features
- ▸Module-based program structure
- ▸Strong typing with explicit type declarations
- ▸Separate compilation units for modularity
- ▸Structured control statements (loops, conditionals)
- ▸Explicit import/export mechanism for modules
Origin & Creator
Modula was created by Niklaus Wirth in 1975 at ETH Zurich as a successor to Pascal with modular programming support.
Industrial Note
Modula is preferred in contexts where strong type safety, modular design, and structured programming are valued, particularly in education and system programming.