This WAT compiles but gives the wrong answer for while (i < 5). Why?
block
loop
local.get $i
i64.const 5
i64.lt_s
br_if 1
;; body
br 0
end
end
Missing i64.eqz. br_if branches when the value is nonzero. i64.lt_s returns 1 when true. So br_if 1 exits when the condition is true -- backwards. i64.eqz flips it: exit when the condition is false (zero).