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:
ret=file_eof(handle)
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.
Share your code
Show a friend, family member, or teacher what you've done!