br_if
Branch to the top of a (loop...) or to the bottom of a (block...) if a condition was met. This will pop an i32 value off the stack and check its value. If it is not zero then it will branch. But if the value is zero then nothing will happen and the following instruction will be performed.

Syntax

br_if $label

Parameters

$label
The name of the code block to branch to. You can also use the index of the code block.

Stack In

i32 The control condition value.

Stack Out

NONE

Example

;; Create loop section
loop $name_of_loop_section
  ;; Do something

  ;; Branch if we need to keep looping
  local.get $keepLooping
  br_if $name_of_loop_section
end  
;; Create block section
block $name_of_block_section
  ;; Do something

  ;; Check age limit
  local.get $age
  i32.const 18
  i32.lt_u
  br_if $name_of_block_section

  ;; Continue to process people over 18
end