Learn Nim - 10 Code Examples & CST Typing Practice Test
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.
Learn NIM with Real Code Examples
Updated Nov 20, 2025
Code Sample Descriptions
Nim Counter and Theme Toggle
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()
Demonstrates a simple counter with theme toggling using Nim variables and console output.
Nim Simple Addition
proc add(a, b: int): int = a + b
echo add(10, 20)
Adds two numbers and prints the result.
Nim Factorial
proc factorial(n: int): int =
if n <= 1: return 1
n * factorial(n - 1)
echo factorial(5)
Calculates factorial recursively.
Nim Fibonacci Sequence
proc fib(n: int): int =
if n < 2: return n
fib(n - 1) + fib(n - 2)
for i in 0..9:
echo fib(i)
Generates first 10 Fibonacci numbers.
Nim Max of Two Numbers
proc max(a, b: int): int = if a > b: a else: b
echo max(10, 20)
Finds the maximum of two numbers.
Nim List Sum
let arr = @[1,2,3,4,5]
echo arr.fold(0, proc(x, y: int): int = x + y)
Sums elements of a sequence.
Nim Even Numbers Filter
let arr = @[1,2,3,4,5]
for x in arr:
if x mod 2 == 0: echo x
Prints even numbers from an array.
Nim Conditional Counter Increment
var count = 3
if count < 5: count += 1
echo count
Increment counter only if less than 5.
Nim Resettable Counter
var count = 0
count += 1
count += 1
echo count
count = 0
echo count
Counter that increments and can be reset.
Nim Theme Toggle Only
var isDark = false
echo if isDark: "Dark" else: "Light"
isDark = not isDark
echo if isDark: "Dark" else: "Light"
isDark = not isDark
echo if isDark: "Dark" else: "Light"
Toggles theme multiple times.
Frequently Asked Questions about Nim
What is Nim?
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.
What are the primary use cases for Nim?
System utilities and command-line tools. Web backends and frameworks. Scientific and numerical computing. Game development and graphics engines. Metaprogramming and code generation
What are the strengths of Nim?
High-performance native binaries. Readable and concise syntax. Powerful metaprogramming capabilities. Cross-platform portability. Flexibility between paradigms (OOP, functional, imperative)
What are the limitations of Nim?
Smaller ecosystem and community compared to mainstream languages. Limited libraries for some specialized domains. Less industrial adoption than Rust or Go. Requires understanding of memory management for optimal performance. Interfacing with large C++ projects can be complex
How can I practice Nim typing speed?
CodeSpeedTest offers 10+ real Nim code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.