Modula-2 Prime Checker - Modula2 Typing CST Test
Loading…
Modula-2 Prime Checker — Modula2 Code
Checks if numbers are prime.
MODULE PrimeCheck;
IMPORT InOut;
VAR nums: ARRAY 3 OF INTEGER := [7,10,13];
VAR n, i: INTEGER;
VAR isPrime: BOOLEAN;
BEGIN
FOR n IN nums DO
isPrime := TRUE;
FOR i := 2 TO n-1 DO
IF n MOD i = 0 THEN isPrime := FALSE END;
END;
InOut.WriteInt(n,0);
IF isPrime THEN InOut.WriteString(" is Prime") ELSE InOut.WriteString(" is Not Prime") END;
InOut.WriteLn;
END;
END PrimeCheck.Modula2 Language Guide
Modula-2 is a statically typed, modular, procedural programming language designed for systems programming and teaching structured programming concepts, created as a successor to Pascal.
Primary Use Cases
- ▸Teaching structured and modular programming
- ▸Systems programming and embedded applications
- ▸Operating system and compiler development
- ▸Prototyping modular software architectures
- ▸Applications requiring strong type safety
Notable Features
- ▸Module system for encapsulation
- ▸Strong static typing
- ▸Procedural programming with structured control
- ▸Separate compilation for modules
- ▸Support for low-level systems programming
Origin & Creator
Developed by Niklaus Wirth in 1978 at ETH Zurich as a follow-up to Pascal, focusing on modularity and systems programming.
Industrial Note
Modula-2 found niche use in teaching programming concepts, embedded systems, and certain early OS development projects, though modern usage is mostly academic.