CSC 272 - Software II: Principles of Programming Languages

Dr. R. M. Siegfried

A BASIC program to Read a File of Numbers

100 REM - Declare Array to be an array
110 DIM ARRAY(10)
120 REM - Comments begin with REM for Remark
130 REM - input reads input from the keyboard after
140 REM - printing an optional prompt
150 REM
160 INPUT "Enter file name "; FILENAME$
170 OPEN FILENAME$ FOR INPUT AS #1
180 REM
190 ARRAYLEN% = 0
200 WHILE NOT EOF(1)
210   ARRAYLEN% = ARRAYLEN% + 1
220   INPUT #1, ARRAY(ARRAYLEN%)
230 WEND
240 FOR I = 1 TO ARRAYLEN%
250   PRINT "X("; I; ") = "; ARRAY(I)
260 NEXT I
270 CLOSE #1
280 END

[Back to the BASIC summary]