1. Home
  2. /
  3. D
  4. /
  5. Counter and Theme Toggle

Counter and Theme Toggle - D Typing CST Test

Loading…

Counter and Theme Toggle — D Code

Demonstrates a simple counter with theme toggling using D variables and console output.

import std.stdio;

int count = 0;
bool isDark = false;

void updateUI() {
	writeln("Counter: ", count);
	writeln("Theme: ", isDark ? "Dark" : "Light");
}

void increment() {
	count += 1;
	updateUI();
}

void decrement() {
	count -= 1;
	updateUI();
}

void reset() {
	count = 0;
	updateUI();
}

void toggleTheme() {
	isDark = !isDark;
	updateUI();
}

// Simulate actions
updateUI();
increment();
increment();
toggleTheme();
decrement();
reset();

D Language Guide

D is a high-level, statically typed, compiled systems programming language combining C-like performance with modern features like garbage collection, functional programming, and meta-programming.

Primary Use Cases

  • ▸Systems programming and OS-level development
  • ▸High-performance computing
  • ▸Game engines and graphics programming
  • ▸Financial and trading applications
  • ▸Compile-time code generation and metaprogramming

Notable Features

  • ▸C-like syntax familiar to C/C++ developers
  • ▸Garbage-collected memory with optional manual management
  • ▸Templates, mixins, and compile-time function execution
  • ▸Contracts, unit tests, and range-based algorithms
  • ▸Cross-platform compilation with high performance

Origin & Creator

Created by Walter Bright in 1999, later developed with contributions from Andrei Alexandrescu.

Industrial Note

D is used in performance-critical applications, game engines, high-performance computing, and financial software requiring fast, reliable code.

More D Typing Exercises

D Simple AdditionD FactorialD Fibonacci SequenceD Max of Two NumbersD Array SumD Even Numbers FilterD Conditional Counter IncrementD Resettable CounterD Theme Toggle Only

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher