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

Counter and Theme Toggle - D 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
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();
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.

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.

Quick Explain

  • ▸D supports imperative, object-oriented, and functional programming paradigms.
  • ▸It offers safe systems-level programming with modern abstractions.
  • ▸Templates, mixins, and compile-time reflection enable advanced metaprogramming.

Core Features

  • ▸Strong static typing with type inference
  • ▸Modules and package system
  • ▸Function overloading, operator overloading
  • ▸First-class functions and closures
  • ▸Compile-time reflection and code generation

Learning Path

  • ▸Learn basic syntax and control flow
  • ▸Understand structs, classes, and interfaces
  • ▸Explore templates and ranges
  • ▸Practice compile-time reflection and mixins
  • ▸Build real-world applications with Dub

Practical Examples

  • ▸Hello world CLI
  • ▸Range-based iteration example
  • ▸Template function for generic containers
  • ▸Class with inheritance and interfaces
  • ▸Compile-time mixin code generation

Comparisons

  • ▸Similar performance to C++
  • ▸Higher-level features than C/C++
  • ▸Easier syntax than C++ templates
  • ▸Smaller ecosystem than Rust or Go
  • ▸Better compile-time metaprogramming than most mainstream languages

Strengths

  • ▸High-performance native code
  • ▸Clean modern syntax with C-style familiarity
  • ▸Powerful compile-time metaprogramming
  • ▸Versatile multi-paradigm language
  • ▸Rich standard library with ranges and algorithms

Limitations

  • ▸Smaller community and ecosystem than C++ or Rust
  • ▸Less industrial adoption for large-scale projects
  • ▸Limited GUI library support
  • ▸Garbage collector can be unpredictable in real-time systems
  • ▸Interfacing with C++ can be complex

When NOT to Use

  • ▸Large-scale GUI-heavy desktop applications
  • ▸Projects needing massive library ecosystems
  • ▸Embedded systems with strict real-time constraints
  • ▸Rapid prototyping with minimal setup
  • ▸Applications requiring maximum portability with minimal compilation

Cheat Sheet

  • ▸import std.stdio;
  • ▸int x = 10;
  • ▸void main() { writeln("Hello World"); }
  • ▸struct S { int a; }
  • ▸template mixinExample() { ... }

FAQ

  • ▸Is D still relevant?
  • ▸Yes - used in high-performance and systems programming.
  • ▸Is D compiled or interpreted?
  • ▸Compiled to native binaries.
  • ▸Is D functional or imperative?
  • ▸Supports imperative, OOP, and functional paradigms.
  • ▸Can D be used for web development?
  • ▸Yes - via Vibe.d and other web libraries.

30-Day Skill Plan

  • ▸Week 1: Syntax, variables, functions
  • ▸Week 2: Classes, structs, inheritance
  • ▸Week 3: Templates, ranges, mixins
  • ▸Week 4: Performance tuning and concurrency

Final Summary

  • ▸D is a versatile systems programming language with high-performance and modern abstractions.
  • ▸Supports multi-paradigm development and compile-time metaprogramming.
  • ▸Ideal for system tools, games, web backends, and scientific computing.

Project Structure

  • ▸src/ - D source files
  • ▸tests/ - unit and integration tests
  • ▸dub.json - project configuration and dependencies
  • ▸examples/ - sample programs
  • ▸docs/ - project documentation

Monetization

  • ▸Game engine development
  • ▸High-performance computing tools
  • ▸Financial software
  • ▸Web backend services
  • ▸System utilities and CLI tools

Productivity Tips

  • ▸Use Dub for project and dependency management
  • ▸Write unittest blocks early
  • ▸Profile and optimize code iteratively
  • ▸Use templates/mixins for repetitive patterns
  • ▸Organize code with modules/packages

Basic Concepts

  • ▸Variables, constants, and types
  • ▸Functions and procedures
  • ▸Control flow: if, while, for, switch
  • ▸Structs, classes, and interfaces
  • ▸Modules, packages, and imports

Official Docs

  • ▸D Language Official Documentation
  • ▸D Language Reference
  • ▸Dub Package Manager Documentation

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