{{fbdoc item="title" value="GOTO"}}----
Control flow statement to jump to another part of the program

{{fbdoc item="syntax"}}##
	**Goto** //label//
##
{{fbdoc item="desc"}}
	Jumps code execution to a line label.
	
	When using ##**Goto** //label//## to exit a scope, any local variables defined in that scope are destroyed (destructors are called).
	
	Usage of ##**Goto** //label//## may be disallowed when it skips a variable definition but not the end of the variable's scope. If the variable requires construction, a compiler error is shown. For other variables, a compiler warning is shown. This is intended to prevent potential accesses to uninitialized variables, and ensures that automatic destruction never happens to an uninitialized variable.
	
	For better source code readability, overuse of ##**Goto**## should be avoided in favor of more modern structures such as ##[[KeyPgDoloop|Do...Loop]]##, ##[[KeyPgFornext|For...Next]]##, ##[[KeyPgSub|Sub]]##, and ##[[KeyPgFunction|Function]]##.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/control/goto.bas"}}%%(freebasic)
	goto there

backagain:
	end

there:
	print "Welcome!"
	goto backagain
%%

{{fbdoc item="filename" value="examples/manual/control/gotonum.bas"}}%%(freebasic)
'' Compile with -lang qb or fblite

'$lang: "qb"

1 Goto 3
2 End
3 Print "Welcome!"
4 Goto 2
%%

{{fbdoc item="lang"}}
	- Line numbers are allowed only in the //[[CompilerOptlang|-lang qb]]// and //[[CompilerOptlang|-lang deprecated]]// dialects.
	- In the //[[CompilerOptlang|-lang qb]]// and //[[CompilerOptlang|-lang fblite]]// dialects, ##**Goto** //label//## is allowed to skip any variable definitions, because nested scopes are not supported and all variable definitions are moved to the top of their procedure.

{{fbdoc item="diff"}}
	- None

{{fbdoc item="see"}}
	- ##[[KeyPgGosub|Gosub]]##
	- ##[[KeyPgSub|Sub]]##
	- ##[[KeyPgFunction|Function]]##
	- ##[[ProPgLabels|Labels]]##

{{fbdoc item="back" value="CatPgControlFlow|Control Flow"}}