{{fbdoc item="title" value="SYSTEM"}}----
Closes all open files and ends the program

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

{{fbdoc item="desc"}}
	Closes all open files, exits the program, and returns to the operating system. An optional return value, an integer, can be specified to return an error code to the system. If no return value is given, a value of 0 is automatically returned. This is the same as ##[[KeyPgEnd|End (Statement)]]## and is here for compatibility between older BASIC dialects. It is recommended to use ##[[KeyPgEnd|End (statement)]]## instead.
	
	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 ##**System**## 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/system/system.bas"}}%%(freebasic)
print "this text is shown"
system
print "this text will never be shown"
%%
{{fbdoc item="diff"}}
	- None

{{fbdoc item="see"}}
	- ##[[KeyPgEnd|End (statement)]]##

{{fbdoc item="back" value="CatPgOpsys|Operating System Functions"}}