noir by example

loops

a for loop can be written a few ways, depending on your needs

use dep::std;

fn main() {
    // loop over a range
    for i in 0..5 {
        std::println(i);
    }

    // over a list, by index
    let foo = [123, 456, 789];
    for i in 0..foo.len() {
        let elem = foo[i];
        std::println(elem);
    }

    // or using for-each style
    for elem in foo {
        std::println(elem);
    }
}

#[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/loops
        nargo test --show-output
        

prev (strings) next (tuples)