GOTO
Jump to navigation
Jump to search
![]() |
![]() |
![]() |
![]() |
Program Flow Control Command
Description
- GOTO 'label' sends the program to the first statement after the 'label'. The 'label' can be a [branchLabel] or a line number. Program flow is transferred to the first statement after the 'label' and continues on.
- See Branch Label.
Syntax
- goto {[branchLabel]} or {line number}
Hints
- GOTO does NOT return to the line following the GOTO statement as does the GOSUB statement.
- Do NOT attempt to leave loop via GOTO bypassing loop terminating operator - there are examples, then exiting loops (FOR, DO, WHILE) with GOTO corrupts JB stack, leading to unexpected behavior.
Example
[numbers] print "1 2 3 4" goto [letters] ' GOTO sends program to branch label and does not return here. print "This text will not print." [letters] print "a b c d" print "This text will print!" print "And then the program will end." end
Useful Procedures
' Place a useful function or sub using this keyword here
Graphics Method
Description
- In a graphics window or graphicbox, GOTO moves the pen from the current position to position x y. A line is drawn if the pen is down. If the pen is up, no line is drawn, but the pen is moved to x y.
- A similar command, place also moves the pen but does not draw a line even if the pen is down.
Syntax
This command is NOT case sensitive.
Using literal values:
- #handle "goto 100 100" - in graphics window
- #handle.ext "goto 100 100" - in graphicbox
Using variable values:
- #handle "goto "; x; " "; y
- #handle.ext "goto "; x; " "; y
- x y are horizontal and vertical coordinates from upper left corner of window.
Hints
- Here is a list of commands that affect the pen position or status:
Example
An example of the command in a graphics window.
nomainwin WindowWidth=400 WindowHeight=300 open "Command Demo" for graphics_nsb_nf as #g #g "trapclose [quit]" 'put pen down #g "down" x=100 : y=100 'move the pen to x y and draw a line #g "goto "; x; " "; y #g "goto 0 270" #g "place 390 0" #g "goto "; x; " "; y #g "goto 390 270" #g "place "; x; " "; y #g "backcolor red" #g "circlefilled 10" wait [quit] close #g end
An example of the command in a graphicbox.
nomainwin WindowWidth=400 WindowHeight=300 graphicbox #g.gb 2, 2, 390, 270 open "Command Demo" for window_nf as #g #g "trapclose [quit]" 'put pen down #g.gb "down" 'move the pen to 100 100 and draw a line #g.gb "goto 100 100" wait [quit] close #g end
Useful Procedures
' Place a useful function or sub using this keyword here