Lesson goal: The End-Of-File (EOF)

Previous: Reading all data from a file (2) | Home | Next: Find the total of some numbers

The issues in the past few lessons were twofold: 1) being able to start a loop to read in all data from a file and 2) knowing when to stop reading from the file.

It turns out in file-lingo, the "end of file" or "EOF" is a very common consideration. When the EOF is reached, we are at the end of a file, and there is no more data to read. If we're in a data-reading loop, it better stop when EOF is reached.

It is so common, most programming languages have a "are we we at the end of a file?" function, that works something like this:

Move the mouse over a dotted box for more information.

Let's see if we can use file-eof and a while-loop to read in all data from a file.

Now you try. __none

Type your code here:

See your results here:

This code is complete. Study it and see if you can understand how file_eof helps.

If everything works, you should see a long list of numbers appear. These will be all of the numbers in the file screen.dat.

For you to do: convert the code to work with the repeat-until loop structure. Dismiss.

Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.