E.1. Control flow statements

WebAssembly has several control flow statements available, like block, loop, and if. Blocks and loops have no effect on the values on the stack and are simply constructs that have a sequence of instructions and a label. A block can be used to specify a label for use with the branching pattern the code needs.

E.1.1. If statements

Writing if blocks is interesting because there are multiple ways that they can be structured. Both the then and else branches of the if block are optional. When using the stack machine style, the then statement is implied. In both styles—stack or nested s-expression—you can use a block statement rather than the then statement because a block statement is just a series of instructions with ...

Get WebAssembly in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.