A Little Fortran

For Chapter 6, Problem 8.

FORTRAN EXPANSION
DO A = 1, 3

  X = X + 1

  ENDDO

 

The FORTRAN DO-loop is an iterative control structure.  It has the form:

DO VARIABLE = INITIAL_VAL, FINAL_VAL, INCREMENT

   ... Code to be executed in loop

  ENDDO

 

VARIABLE is a counter for the loop.

When the loop is entered, VARIABLE is initialized to INITIAL_VAL.

After the code inside the do-loop is executed, the counter VARIABLE is incremented by INCREMENT.  It is then tested against the ending value, FINAL_VAL.  If VARIABLE is not greater than FINAL_VAL, the loop is executed again.  If VARIABLE is greater than FINAL_VAL, the program continues with the statement following ENDDO.

 

(X has some initial value prior to entering the loop.)

A = 1

IF A > 3 THEN EXIT

X = X + 1

A = A + 1  (A now equals 2)

IF A > 3 THEN EXIT

X = X + 1

A =  A + 1  (A now equals 3)

IF A > 3 THEN EXIT

X = X + 1

A = A + 1 (A now equals 4)

IF A > 3 THEN EXIT

EXIT

 

 

 

 

For Chapter 6, Problem 10.

FORTRAN MEANING
READ *, X Read the next input record from the standard input device and place the results into variable X.

The asterisk occupies the position that belongs to a number than identifies an input or output device. 

IF (X .EQ. 0) Y(I) = 0

IF (X .NE. 0) Y(I) = 10

Y(I) is the I-th element of array Y.

An array is a set of contiguous data elements that are referred to by a common name.  In this example, the array name is Y.

Elements of an array are located by an index.  The index is a number.  In this example, the index is I.

In the IF statements, the relational operator  .EQ.  means "equal", and the relational operator  .NE.  means "not equal". 

A BASIC version of these statements:

IF  X = 0  THEN  Y(I) = 0

IF  X <> 0  THEN Y(I) = 10