1. Home
  2. /
  3. Modula2 Typing Test
  4. /
  5. Modula-2 Counter and Theme Toggle

Modula-2 Counter and Theme Toggle - Modula2 Typing CST Test

Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
MODULE CounterTheme;

VAR
count: INTEGER := 0;
isDark: BOOLEAN := FALSE;

PROCEDURE updateUI;
BEGIN
WriteString("Counter: "); WriteInt(count, 0); WriteLn;
IF isDark THEN
WriteString("Theme: Dark"); WriteLn
ELSE
WriteString("Theme: Light"); WriteLn;
END;
END updateUI;

PROCEDURE increment;
BEGIN
count := count + 1;
updateUI;
END increment;

PROCEDURE decrement;
BEGIN
count := count - 1;
updateUI;
END decrement;

PROCEDURE reset;
BEGIN
count := 0;
updateUI;
END reset;

PROCEDURE toggleTheme;
BEGIN
isDark := NOT isDark;
updateUI;
END toggleTheme;

BEGIN
updateUI;
increment;
increment;
toggleTheme;
decrement;
reset;
END CounterTheme.
Coding works best on desktop or with an external keyboard.
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.

Modula-2 Counter and Theme Toggle — Modula2 Code

Demonstrates a simple counter with theme toggling using Modula-2 variables and procedures.

MODULE CounterTheme;

VAR
	count: INTEGER := 0;
	isDark: BOOLEAN := FALSE;

PROCEDURE updateUI;
BEGIN
	WriteString("Counter: "); WriteInt(count, 0); WriteLn;
	IF isDark THEN
		WriteString("Theme: Dark"); WriteLn
	ELSE
		WriteString("Theme: Light"); WriteLn;
	END;
END updateUI;

PROCEDURE increment;
BEGIN
	count := count + 1;
	updateUI;
END increment;

PROCEDURE decrement;
BEGIN
	count := count - 1;
	updateUI;
END decrement;

PROCEDURE reset;
BEGIN
	count := 0;
	updateUI;
END reset;

PROCEDURE toggleTheme;
BEGIN
	isDark := NOT isDark;
	updateUI;
END toggleTheme;

BEGIN
	updateUI;
	increment;
	increment;
	toggleTheme;
	decrement;
	reset;
END CounterTheme.

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.

Quick Explain

  • ▸Modula-2 emphasizes modularity, strong typing, and separate compilation of modules.
  • ▸It introduces a module system to organize code, enabling encapsulation and namespace management.
  • ▸Widely used in academia for teaching structured and systems programming, and in embedded or systems-level applications.

Core Features

  • ▸Procedures, functions, and type-safe operations
  • ▸Modules with exported and hidden interfaces
  • ▸Record and array data structures
  • ▸Set, pointer, and enumeration types
  • ▸Control structures: IF, CASE, WHILE, FOR, REPEAT

Learning Path

  • ▸Learn basic Pascal syntax
  • ▸Understand modules and separate compilation
  • ▸Practice writing procedures and functions
  • ▸Explore records, arrays, and pointers
  • ▸Build small modular projects

Practical Examples

  • ▸Implementing a modular calculator
  • ▸Creating a library of reusable procedures
  • ▸Building simple file I/O applications
  • ▸Developing a small embedded system module
  • ▸Constructing compiler or interpreter components

Comparisons

  • ▸Successor to Pascal with modular features
  • ▸Stronger type safety and separate compilation
  • ▸Less flexible than modern object-oriented languages
  • ▸Excellent for structured and systems programming
  • ▸Smaller ecosystem than C or Python

Strengths

  • ▸Enforces disciplined programming with strong typing
  • ▸Supports modular software design
  • ▸Good for systems programming and low-level operations
  • ▸Readable syntax similar to Pascal
  • ▸Facilitates separate compilation and encapsulation

Limitations

  • ▸Limited modern library ecosystem
  • ▸Mostly academic or legacy use today
  • ▸No native support for GUI programming
  • ▸Not widely adopted in industry
  • ▸Less flexible compared to modern object-oriented languages

When NOT to Use

  • ▸Modern web or mobile development
  • ▸GUI-intensive applications
  • ▸High-level scripting or automation tasks
  • ▸Projects requiring extensive third-party libraries
  • ▸Enterprise software expecting active community support

Cheat Sheet

  • ▸MODULE Name; … END Name. - define module
  • ▸IMPORT ModuleName; - use another module
  • ▸VAR x: INTEGER; - declare variable
  • ▸PROCEDURE Foo(); - define procedure
  • ▸BEGIN … END; - block or program body

FAQ

  • ▸Is Modula-2 still used?
  • ▸Mostly academic or legacy systems; active development is minimal.
  • ▸Can Modula-2 handle low-level programming?
  • ▸Yes, it supports pointers and system-level operations.
  • ▸Does Modula-2 support modularity?
  • ▸Yes, with a clear module interface and implementation separation.
  • ▸Is Modula-2 object-oriented?
  • ▸No, it is procedural and modular, not object-oriented.
  • ▸Is Modula-2 cross-platform?
  • ▸Compilers exist for Windows, Linux, and some legacy OSes.

30-Day Skill Plan

  • ▸Week 1: Variables, types, and control structures
  • ▸Week 2: Procedures, functions, and modules
  • ▸Week 3: Records, arrays, and pointers
  • ▸Week 4: Multi-module projects and linking
  • ▸Week 5: Systems programming exercises

Final Summary

  • ▸Modula-2 is a modular, strongly typed procedural language.
  • ▸Designed for systems programming, teaching, and structured software design.
  • ▸Emphasizes separate compilation and module encapsulation.
  • ▸Mostly used in academic and legacy contexts today.
  • ▸Introduced concepts foundational to later languages like Oberon.

Project Structure

  • ▸Modules/ - source code files
  • ▸Definitions/ - module interface files
  • ▸Lib/ - standard or third-party libraries
  • ▸Bin/ - compiled object files and executables
  • ▸Docs/ - documentation and project notes

Monetization

  • ▸Academic teaching materials
  • ▸Embedded system solutions
  • ▸Legacy system maintenance
  • ▸Consulting on structured programming
  • ▸Specialized industrial applications

Productivity Tips

  • ▸Organize code into reusable modules
  • ▸Use descriptive procedure and variable names
  • ▸Separate interface and implementation cleanly
  • ▸Keep module dependencies minimal
  • ▸Document interfaces for clarity

Basic Concepts

  • ▸Variables, constants, and types
  • ▸Procedures and functions
  • ▸Modules for encapsulation
  • ▸Control structures (IF, CASE, loops)
  • ▸Data structures: arrays, records, sets, pointers

Official Docs

  • ▸Niklaus Wirth Modula-2 publications
  • ▸ISO/IEC 10514 standard documents
  • ▸Compiler manuals (XDS Modula-2, GNU Modula-2)

More Modula2 Typing Exercises

Modula-2 Random Number GeneratorModula-2 Todo ListModula-2 Dice RollerModula-2 Countdown TimerModula-2 Prime CheckerModula-2 Temperature ConverterModula-2 Shopping CartModula-2 Name GreetingModula-2 Stopwatch

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher