cairo by example

booleans

As with Boolean types in other programming languages, bools have only two possible values: true and false.

fn main() {
    let t: bool = true;
    let true_expr = 5 == 5;
    assert(t == true_expr, 'this is true');

    let f: bool = false;
    let false_expr = 7 == 5;
    assert(f == false_expr, 'this is false');
}

As with other scalar types, they are one felt252 in size.



Try it out!
  1. Install the toolchain:
    • For macOS and Linux, run our script:
    • curl -sL https://raw.githubusercontent.com/lambdaclass/cairo-by-example/main/build/installer.sh | bash -s 2.2.0
    • For Windows and others, please see the official guide
  2. Run the example:
    1. Copy the example into a booleans.cairo file and run with:
    2. %!s(<nil>) booleans.cairo

prev (integers) next (primitive-types)