{{fbdoc item="title" value="END (Statement)"}}----
Control flow statement to end the program.

{{fbdoc item="syntax"}}##
	[[KeyPgDeclare|declare]] [[KeyPgSub|sub]] **End** ( [[KeyPgByval|byval]] //retval// [[KeyPgAs|as]] [[KeyPgLong|long]] = 0 )
##
{{fbdoc item="usage"}}##
	**End** [ //retval// ]
##
{{fbdoc item="param"}}
	##//retval//##
		Error code returned to system.

{{fbdoc item="desc"}}
	Used to exit the program, and return to the operating system. An optional integer return value can be specified to indicate an error code to the system. If no return value is given, a value of ##0## is automatically returned at the end of the program.
	
	Usage of this statement does not cleanly close scope. Local variables will not have their destructors called automatically, because ""FreeBASIC"" does not do stack unwinding. Only the destructors of global variables will be called in this case.
	
	For this reason, it is discouraged to use ##**End**## simply to mark the end of a program; the program will come to an end automatically, and in a cleaner fashion, when the last line of module-level code has executed.

{{fbdoc item="ex"}}
	{{fbdoc item="filename" value="examples/manual/control/end.bas"}}%%(freebasic)
'' This program requests a string from the user, and returns an error
'' code to the OS if the string was empty

function main() as integer

	'' assign input to text string
	dim as string text
	line input "Enter some text ( try ""abc"" ): " , text

	'' If string is empty, print an error message and
	'' return error code 1 (failure)
	if( text = "" ) then
		print "ERROR: string was empty"
		return 1
	end if

	'' string is not empty, so print the string and
	'' return error code 0 (success)
	print "You entered: " & text
	return 0

end function

'' call main() and return the error code to the OS
end main()
%%
{{fbdoc item="target"}}
	- In Linux, the ##//retval//## parameter is a ##[[KeyPgByte|byte]]##.

{{fbdoc item="diff"}}
	- The END statement supports specifying a custom return value to be returned to the operating system.

{{fbdoc item="see"}}
	- ##[[KeyPgEndblock|End (Block)]]##
	- ##[[KeyPgReturn|Return (from procedure)]]##
	- ##[[KeyPgReturnGosub|Return (from Gosub)]]##

{{fbdoc item="back" value="CatPgMisc|Miscellaneous"}}