noir by example

if / else

noir supports conditionals through typical if / else if / else chains

fn main(foo: u32, mut bar: [u32; 2]) -> pub bool {
    if foo == bar[0] {
        true
    } else if foo == bar[1] {
        true
    } else {
       false
    }
}

#[test]
fn test_main() {
    let mut found = main(4, [2, 4]);
    assert(found == true);

    found = main(42, [2, 4]);
    assert(found == false);
}

try it out install the noir toolchain if you haven't yet:
        curl -L https://noirup.org/install | bash
        noirup --nightly
        
then checkout and run the example:
        git clone https://github.com/sambarnes/noir-by-example.git
        cd noir-by-example/circuits/examples/if-else
        nargo test --show-output
        

prev (functions) next (strings)