Warning

You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
on [2019/06/08 22:14] neilson [2019/06/09 08:26] (current) – [Performance tip] neils
Line 4: Line 4:
  
   on <byte or int index> goto label [ ,label ...]   on <byte or int index> goto label [ ,label ...]
 +
 +or:
 +
   on <byte or int index> gosub label [ ,label ...]   on <byte or int index> gosub label [ ,label ...]
      
Line 13: Line 16:
  
 **Note #2:** The runtime will not check if //index// is within the number of labels. If //index// is larger than the number of labels minus one, the program will (most probably) break. **Note #2:** The runtime will not check if //index// is within the number of labels. If //index// is larger than the number of labels minus one, the program will (most probably) break.
 +
 +Example:
 +
 +  rem -- i! holds a value between 0 and 2 
 +  on i! goto case0, case1, case2
 +  end
 +  case0:
 +    print "i! equals 0"
 +    end
 +  case1:
 +    print "i! equals 1"
 +    end
 +  case2:
 +    print "i! equals 2"
 +    end
 +    
 +====== Performance tip ======
 +
 +An ''ON ... GOTO'' or ''ON ... GOSUB'' construct is faster than its ''IF ... THEN GOTO/GOSUB'' equivalent. It's especially useful when branching on a TRUE/FALSE condition, for example:
 +
 +  rem -- branching using IF ... THEN
 +  rem -- assume x! is a zero or one (TRUE/FALSE) value
 +  
 +  if x! = 0 then goto false_case else goto true_case
 +  
 +  rem -- same as above but FASTER
 +  
 +  on x! goto false_case, true_case