next up previous contents
Next: GOTO Statements Up: Introduction to FORTRAN Previous: Constants, Variables, Expressions and

   
PRINT, READ, STOP and END statements

We have already seen that PRINT sends data to the user's terminal. READ does the reverse, it takes data from the user's terminal and stores it in variables. The general form of these two statements are as follows:-
PRINT format reference,I/O list
READ format reference,I/O list

The format reference indicates how the data is to be formatted; for now we shall only consider the special reference * which gives a very simple data format. See section 9 for further information. The I/O list (I/O stands for Input Output) is a list of variable names separated by commas. In the case of PRINT it can also contain character strings within ' (the single quote).

Exercise 3
Type in the following program and run it:-

      PRINT *,'PLEASE TYPE IN 2 NUMBERS'
      READ *,A,B
      C=A+B
      PRINT *,A,' +' ,B,' = ',C
      STOP
      END

When the program executes the first line it will type out the message and when it reaches READ it will wait for the user. Type in 2 numbers separated by a comma and then press RETURN. The program should now continue and type the results. Note one important point, READ should always be proceeded by PRINT so that the user is aware that the program is waiting for data from him or her. PRINT and READ are I/O statements. Input i.e. transfer of data into the program is also called reading, while output is called writing. The FORTRAN statements READ and WRITE are described in more detail in section 10

* * *

All sample programs shown so far end with the statements STOP and END. STOP tells the computer to stop running the program. In principle STOP can appear anywhere in the program and there can be any number of them. END tells the compiler (i.e. the program that takes your FORTRAN source and converts it into machine code) that this is the end of a program unit for compilation. There can only be one END in a program unit and it must be the last line.


next up previous contents
Next: GOTO Statements Up: Introduction to FORTRAN Previous: Constants, Variables, Expressions and
n west (APC)
2000-03-08