Language Guide / Syntax & Blocks

Syntax & Blocks

Lexical rules, reserved keywords, comments, indentation vs end blocks, show, and assert.

Lexical Structure

Reserved Keywords

Dlang reserves 22 keywords that cannot be used as variable or function names:

keywords
fn       end      return   if       else     while    for      in
break    continue show     assert   import   match    pub      private
true     false    missing  and      or       not

Indentation and end Blocks

Blocks (fn, if, else, while, for, match) support both indentation-based scoping and explicit end terminators. Never mix tabs and spaces in the same file.

blocks.dl
# Indentation-only block
fn greet(name)
    show "hello " + name

# Explicit end terminator
if true
    show "yes"
end

Output & Assertions

show expr prints a value followed by a newline. assert expr aborts at runtime if expr is not true.

io.dl
name = "dlang"
show name
assert len(name) == 5