loop
Branching to a loop label jumps back to the top, like continue in other languages. Combine with an outer block for a clean break target.
(module (func (param $n i32) (result i32) (local $acc i32) (block $done (loop $again (br_if $done (i32.eqz (local.get $n))) (local.set $acc (i32.add (local.get $acc) (i32.const 1))) (local.set $n (i32.sub (local.get $n) (i32.const 1))) (br $again))) (local.get $acc)))br $againjumps to the top of the loop.br_if $doneexits the outer block when$nreaches zero.
Instruction Reference
Section titled “Instruction Reference”- Control Flow Instructions —
block,loop,br,br_if