noir by example

variables

store data in variables with the let keyword

if you need to change that data, it must be marked “mutable” with mut

fn main() {
    let immutable_var = 17;
    // immutable_var = 38;  <-- fails to compile

    // but this is legal:
    let mut mutable_var = immutable_var;
    mutable_var = 38;

    assert(mutable_var != immutable_var);
}

#[test]
fn test_main() {
    main();
}

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/variables
        nargo test --show-output
        

prev (assert) next (functions)