> You can think of the "br" as "branch" instead of break
Yes, but the branch target depends on the targeted block's kind: it's the block-exit label for ifs and blocks and the block-start for loops. Just a bit unusual.
> We didn't have different instructions for branching depending on the type of the label because it's not necessary, just a waste of opcode space.
Yeah, I understand that, but it still could be two different mnemonics: 0x0C/0x0D could disassemble as "continue/continue_if" if the label targets a loop, and as "break/break_if" if it targets a non-loop; similarly for assembling. I imagine the added overhead would be minuscule.
Anyway, thanks for answering. I suppose forcing the structured control flow in the IR beats e.g. simplicity of compiling a for-loop in one pass.
block
;; code for INITIALIZATION
loop
;; code for CONDITION
i32.eqz
br_if 1
i32.const 0
loop
if
;; code for INCREMENT
br 2
end
;; code for BODY
i32.const 1
br 0
end
end
end