Skip to content
Kavachकवच

Booleans

Also known as: boolean bool true false logic and or not truthy falsy

● Beginner3 minBefore this: OperatorsSpec 2.1

A Bool is true or false. Comparisons make them, and and, or, not combine them.

fn main() {
    const sunny = true
    const age = 17
    const adult = age >= 18
    print(sunny)
    print(adult)
}

The program ran and printed:

kavach run bool.kav

truefalse
bool.kav: Kavach code, then what running it prints
fn main() {
    const age = 25
    const member = false
    print(age >= 18 and member)
    print(age >= 18 or member)
    print(not member)
}

The program ran and printed:

kavach run logical.kav

falsetruetrue
logical.kav: Kavach code, then what running it prints

Only a Bool is a condition

Some languages treat 0, empty text or none as false. Kavach doesn't, and says what to write instead:

fn main() {
    const count = 3
    if count {
        print("some")
    }
}

The compiler refused the program:

kavach run truthy.kav

error: conditions must be `Bool`, not `Int`: there is no truthiness, so compare explicitly (for example `!= 0`)
truthy.kav: Kavach code, then what running it prints