{{fbdoc item="title" value="EOF"}}----
Checks to see if the end of an open file has been reached

{{fbdoc item="syntax"}}##
	[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Eof** ( [[KeyPgByval|byval]] //filenum// [[KeyPgAs|as]] [[KeyPgLong|long]] ) [[KeyPgAs|as]] [[KeyPgLong|long]]
##
{{fbdoc item="usage"}}##
	//result// = **Eof**( //filenum// )
##
{{fbdoc item="param"}}
	##//filenum//##
		File number of an open file.

{{fbdoc item="ret"}}
	Returns true (-1) if end-of-file has been reached, zero (0) otherwise.

{{fbdoc item="desc"}}
	When reading from files opened for ##[[KeyPgInputfilemode|Input (File Mode)]]##, it is useful to know when the end of the file has been reached, thus avoiding errors caused by reading past the ends of files. Use EOF to determine this. EOF expects a valid file number from an already opened file. Use ##[[KeyPgFreefile|Freefile]]## to retrieve an available file file number.
	
	For file numbers bound to files opened for ##[[KeyPgOutput|Output]]##, EOF always returns 0.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/fileio/eof.bas"}}%%(freebasic)
'' This code finds a free file number to use and attempts to open the file
'' "file.ext" and if successful, binds our file number to the opened file. It
'' reads the file line by line, outputting it to the screen. We loop until eof()
'' returns true, in this case we ignore the loop if file is empty.

dim as string file_name
dim as integer file_num

file_name = "file.ext"
file_num = freefile( )                 '' retrieve an available file number

'' open our file and bind our file number to it, exit on error
if( open( file_name for input as #file_num ) ) then
   print "ERROR: opening file " ; file_name
   end -1
end if

do until eof( file_num )               '' loop until we have reached the end of the file
   dim as string text
   line input #file_num, text               '' read a line of text ...
   print text                             '' ... and output it to the screen
loop

close #file_num                        '' close file via our file number

end 0
%%

{{fbdoc item="diff"}}
	- In QB the comm port signaled an EOF when there were no chars waiting to be read.
	- In QB, for files opened in RANDOM or BINARY mode, EOF returned non-zero only after a read past the end of file has been attempted.  In FreeBASIC, EOF returns true after the last item is read.

{{fbdoc item="see"}}
	- ##[[KeyPgLof|Lof]]##
	- ##[[KeyPgLoc|Loc]]##
	- ##[[KeyPgFreefile|Freefile]]##

{{fbdoc item="back" value="CatPgFile|File I/O Functions"}}