Boolean type

The boolean type is named bool in Nim and can be one of the two pre-defined values true and false. Conditions in while, if, elif, when-statements need to be of type bool.

This condition holds:

  1. ord(false) == 0 and ord(true) == 1

The operators not, and, or, xor, <, <=, >, >=, !=, == are defined for the bool type. The and and or operators perform short-cut evaluation. Example:

  1. while p != nil and p.name != "xyz":
  2. # p.name is not evaluated if p == nil
  3. p = p.next

The size of the bool type is one byte.