5

As titled, the spec says that "loop" is

a block with a label at the beginning which may be used to form loops.

and for "block":

the beginning of a block construct, a sequence of instructions with a label at the end.

But with the help of "br" (used for switching branch to a labeled block), I can form the same control structure even with "block", right?. So, what's the difference between these two instructions?

Jason Yu
  • 1,886
  • 16
  • 26

2 Answers2

7

A br to a block label jumps to the end of the contained instruction sequence -- it behaves like a break statement in C.

A br to a loop label jumps to the start of the contained instruction sequence -- it behaves like a continue statement in C.

The former enables a forward jump, the latter a backwards jump. Neither can express the other.

Andreas Rossberg
  • 34,518
  • 3
  • 61
  • 72
0

No you can't block has the label at end as it sayed block has the label at the end

LOOP START
label:
SOME CODE
IF condtion BR label:
EVEN MORE CODE
LOOP END

Will execute SOME CODE once. Than repeats SOME CODE until condition is not true. And than execute EVEN MORE CODE

BLOCK START
SOME CODE
IF condition BR label:
EVEN MORE CODE
label:
BLOCK END

Will execute SOME CODE only once. And than EVEN MORE CODE might be execute when contdtion is not true.

Lee
  • 1,427
  • 9
  • 17