100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Nim Cheat Sheet

Nim Cheat Sheet

Practical Nim syntax covering variables, types, control flow, procedures, and sequences for a Python-like compiled language.

2 PagesIntermediateApr 15, 2026

Basics

Variables and procedures.

nim
# Variables and printinglet name = "World"          # immutablevar counter = 0               # mutableecho "Hello, ", name, "!"echo "Value: ", counterproc add(a, b: int): int =  a + b                        # implicit return of last expressionecho add(2, 3)

Types & Objects

Built-in types and a custom object type.

nim
var x: int = 42var y: float = 3.14var s: string = "text"var flag: bool = truetype  Point = object    x, y: floatvar p = Point(x: 1.0, y: 2.0)echo p.x, " ", p.y

Control Flow

Conditionals and loops.

nim
let n = 10if n > 5:  echo "big"elif n == 5:  echo "equal"else:  echo "small"for i in 0..4:  echo "i=", ivar count = 0while count < 3:  inc count

Procs & Functions

Defining and annotating procedures.

  • proc name(args): ReturnType = ...- Defines a procedure (function)
  • func- Shorthand for a proc that has no side effects
  • result- Implicit return variable, auto-returned at the end of a proc
  • discard expr- Explicitly ignores a return value
  • {.inline.}- Pragma requesting the compiler inline a proc
  • proc greet(name: string = "World")- Declares a default parameter value

Collections

Sequences, arrays, and tables.

  • @[1, 2, 3]- Sequence (dynamic array) literal
  • [1, 2, 3]- Fixed-size array literal
  • {"a": 1, "b": 2}.toTable- Creates a hash table
  • seq[int]- Sequence type holding ints
  • for x in mySeq: echo x- Iterates a sequence
  • mySeq.add(4)- Appends an element to a sequence
Pro Tip

Nim compiles to C and lets you drop into low-level control with pragmas or ptr types for hot loops, while keeping high-level, Python-like syntax everywhere else.

Was this cheat sheet helpful?

Explore Topics

#Nim#NimCheatSheet#Programming#Intermediate#TypesObjects#ControlFlow#ProcsFunctions#Collections#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet