Skip to content

Booleans

bool has two values, true and false, produced by comparisons and combined with the logical operators:

Booleans and nil — the two simplest values in the language.

04-bool-and-nil.zolo
Playground
// Feature: bool, nil, optional `T?`
// Syntax: `true` / `false` / `nil`; `T?` for optional types
// When to use: boolean logic; `nil` for "absence"; `T?` for values
// that may be missing in the type system.

// Booleans.
let active = true
let done: bool = false

// Short-circuit in && and ||
let a = active && 1 < 2  // true
let b = done || 1 == 1  // true
print(a, b)

// Logical negation.
print(!active)  // false

// `nil` is the "empty" value — the only value of its type.
let nothing = nil
print(nothing)  // nil

// Truthiness: only `nil` and `false` are falsy. 0, "", []
// COUNT as truthy (Lua semantics).
if 0 { print("0 is truthy") }
if "" { print("empty string is truthy") }
if [] { print("empty array is truthy") }

// Optional: `T?` accepts `T` OR `nil`.
let name: str? = nil
if name == nil {
  print("no name")
}

// Use `??` for fallback.
let display = name ?? "anonymous"
print(display)  // anonymous
enespt-br