Contents Previous Next Subchapters

Transferring Control Using The Goto Statement
Syntax label label name
label name
See Also if , break , halt

The goto statement transfers execution to the point specified by label name.

The goto and label statements must be within a block (a begin/end pair).

The goto statement can be used to calculate a factorial, as was done in the examples of for and while statements. For example, to calculate 5!, you would enter
     fact = 1
     i    = 1
          label loop
          fact = fact * i
          i    = i + 1
          if i <= 5 then goto loop
     print fact
to which O-Matrix will respond
You can use the goto statement to jump out of a for or while loop. If you enter
          for i = 1 to 5 begin
               if i > 3 then goto done
               print i
          label done
O-Matrix will respond