Noir’s control flow syntax closely follows Rust. One important difference is thatDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/noir-lang/noir/llms.txt
Use this file to discover all available pages before exploring further.
loop and while are only available in unconstrained contexts — constrained code requires that the number of loop iterations is known at compile time.
if / else
if is an expression in Noir, not just a statement. Parentheses around the condition are not required:
if is an expression, you can use it on the right-hand side of a binding:
Noir has no
|| or && operators. Use the bitwise | and & operators instead — they are equivalent for booleans but do not short-circuit (which would be inefficient in ZK circuits).for loops
for loops iterate over a compile-time-known range. The index type is u64:
..= for an inclusive range:
loop (unconstrained only)
loop creates an infinite loop that must be exited with break. It is only valid in unconstrained code:
loop must contain at least one reachable break statement.
while (unconstrained only)
while loops run as long as a condition is true. They are only valid in unconstrained code:
break and continue
break and continue are only available inside unconstrained code. They cannot jump out of more than one loop at a time:
breakexits the current loop and jumps to the statement after it.continuestops the current iteration and jumps to the start of the next one. The iteration variableiis still incremented normally.
assert and assert_eq
assert enforces a constraint. If the condition is false, proof generation fails:
assert_eq is shorthand for asserting two values are equal:
Shadowing
Noir supports variable shadowing. A newlet binding with the same name as an existing variable creates a new binding in the current scope:
Mutability
Variables are immutable by default. Usemut to allow reassignment:
mut modifier can apply to patterns: