(if...)
Create an if...then...else
block. The instruction will pop a i32
value of the stack.
If the value is not a zero then the then
code block section is performed. But, if the value is zero, then
the else
section is processed, if it exists.
Syntax
if
...
end
if
...
else
...
end
(if
(then
...
)
)
(if
(then
...
)
(else
...
)
)
(if
(
)
(then
...
)
(else
...
)
)
if (param...) (result...)
...
else
...
end
Parameters
(param...) Optional
Lists all the values on the stack that will be used inside the code block. This can only be used if there is an else
section.
Both sections need to pop the same number of values off the stack.
(result...) Optional
Lists all the values that will be pushed onto the stack when the execution moves out of the code block.
This can only be used if there is an else
section.
Both sections need to push the same number of values onto the stack.
Stack In
i32 |
The control condition value. |
Examples
i32.const 1
if
else
end
i32.const 42
i32.const 1
if (param i32) (result i32)
i32.const 10
i32.add
else
i32.const 20
i32.add
end