GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Download
  • News
  • Community
  • Resources
  • Language Reference
  • SmallBASIC Manual

This view

  • Original page
  • New address

GeezerVison is showing smallbasic.github.io — SmallBASIC | GOTO

Edit History

GOTO

GOTO label

Home > Reference > Language

Causes program execution to branch to a specified position (label).

GOTO is known to create “spaghetti code”, i.e. winding code which is hard to follow, to understand, and to maintain. IF…THEN, SELELCT CASE, SUB, FUNC and DEF are much better ways to write branching code.

See ON for ON n GOTO Label1 for branching depending on a number n.

Example 1

label FirstLine
    
ii++
print ii
if(ii == 10) then goto LastLine 
goto FirstLine

label LastLine

Example 2

randomize

While True 
  x = Rnd
  tries++
  
  While True
    If x < 0.05 Then 
      Print "x < 0.05 (after "; tries; " tries)."
      Goto exitLoops ' here we exit all loops unconditionally.
    Elif tries = 10 Then
      Print "missed! (after "; tries; " tries)."
      Goto exitLoops ' here we exit all loops unconditionally.
    Else
      Exit Loop ' here we exit only the inner WHILE loop
    Fi
  Wend
  
Wend

Label exitLoops
Print
Print "Out of loops now."
Code samples using GOTO
004 loops.bas   3d_palmx.bas   3dtictac.bas   3dttt.bas   3dttt.bas   7gables.bas   ai.bas   amortig.bas   anball 1.0.bas   Balleta 2-11-15.bas   BAS_1968.bas   BAS_NOW.bas   betrayal: crows ii.bas   biorythms.bas   blackbox.bas   Blackbox.bas   blackjack.bas   BlackJack.bas   bmpreal.bas   bolmo.bas   conrec-sb-v01.bas   crow.bas   dataminmax.bas   demanda.bas   dogstar5.bas   duty.bas   Easter_Butcher.bas   easter_butcher.bas   Easter_Carter.bas  
Language
AND   AS   BAND   BG   BOR   BYREF   CALL   CASE   CATCH   CONST   DECLARE   DEF   DO   ELIF   ELSE   ELSEIF   END   END TRY   ENDIF   EQV   EXIT   FALSE   FI   FOR   FUNC   GOSUB   GOTO   IF   IFF   IMP   IN   LABEL   LET   LIKE   LOCAL   LSHIFT   MDL   MOD   NAND   NEXT   NOR   NOT   ON   OR   REM   REPEAT   RETURN   RSHIFT   SELECT   STEP   STOP   SUB   THEN   THROW   TO   TRUE   TRY   UNTIL   USE   USG   USING   WEND   WHILE   XNOR   XOR  
This page was last edited on Fri, 9 Jun 2023 14:42:08 +0200 | Markdown processed with pandoc 3.1.12.1
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.