GOTO
GOTO label
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
Rnd
x =
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
If there is insufficient information on this page and you wish learn more about GOTO,
please send an email to smallbasic@gmail.com. You can help to improve information about
GOTO by submitting a pull request,
click View Source for details. Note, an offline language reference text file is also available - see the Download section.