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

Counter and Theme Toggle - Nim Typing CST Test

Loading…

Counter and Theme Toggle — Nim Code

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

var count = 0
var isDark = false

proc updateUI() =
	echo "Counter: ", count
	echo "Theme: ", if isDark: "Dark" else: "Light"

proc increment() =
	count += 1
	updateUI()

proc decrement() =
	count -= 1
	updateUI()

proc reset() =
	count = 0
	updateUI()

proc toggleTheme() =
	isDark = not isDark
	updateUI()

# Simulate actions
updateUI()
increment()
increment()
toggleTheme()
decrement()
reset()

Nim Language Guide

Nim is a statically typed, compiled systems programming language with Python-like syntax. It emphasizes performance, expressiveness, and metaprogramming, making it suitable for system tools, web development, and scientific computing.

Primary Use Cases

  • ▸System utilities and command-line tools
  • ▸Web backends and frameworks
  • ▸Scientific and numerical computing
  • ▸Game development and graphics engines
  • ▸Metaprogramming and code generation

Notable Features

  • ▸Python-like clean syntax
  • ▸Compile-time metaprogramming with macros
  • ▸Memory safety with manual or garbage-collected management
  • ▸Cross-platform compilation to C/C++/JS
  • ▸Lightweight concurrency support with async/await

Origin & Creator

Created in 2008 by Andreas Rumpf.

Industrial Note

Nim is used in high-performance tools, embedded systems, game development, and niche web frameworks where low-level control and speed are essential.

More Nim Typing Exercises

Nim Simple AdditionNim FactorialNim Fibonacci SequenceNim Max of Two NumbersNim List SumNim Even Numbers FilterNim Conditional Counter IncrementNim Resettable CounterNim Theme Toggle Only

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher