0

It seems like blocks and loops can be synonymous to each other

block $loop
   foo
   br $loop
end

Here the branch instruction would transfer the control to the end which acts like a "break".

In case of a loop,

loop $loop
   foo
   br $loop
end

Here the control is transferred to the beginning.

This is confusing because I could write either synonymously to each other by removing the "br" and either would work as a normal loop with "break" and "continue" from what I can see. So, which one should be used when, and what is the reasoning behind this design choice? Is it trying to solve a particular problem with other ISAs?

I found this thread What's the difference between "block" and "loop" in WebAssembly spec? which talks about forward/backward jumpers, but I am still confused. A simple explanation about their use cases would be really nice!

0xfffe
  • 1
  • 1
  • 1

0 Answers0