P33.F90

IF-THEN-ELSE construct


!
! =====> Program - P33.F90
!
!
!     Simple loop with IF-THEN-ELSE
!
!
      PRINT *, 'This is Program >> P33  - IF-THEN-ELSE'
!
!
!     Tell program where data for  READ *  is coming from
      OPEN(UNIT=5, FILE='P33.DAT')      ! UNIT=5 is the default input
!
      DO
          READ *,SUM ,COUNT
          IF(COUNT  ==  0.0) THEN
             PRINT *,'COUNT ZERO'
             STOP
          ELSE
             AVE=SUM/COUNT
             PRINT *,'SUM=', SUM
             PRINT *,'COUNT=', COUNT
             PRINT *,'AVERAGE=', AVE
          ENDIF
      END DO
      END

DATA:
120.0   10.0
100.0    0.0

OUTPUT:
Program entered
 This is Program >> P33  - IF-THEN-ELSE
 SUM=   1.2000000E+02
 COUNT=  10.0000000
 AVERAGE=  12.0000000
 COUNT ZERO
Fortran-90 STOP

Come back to the previous page

Page builder: Charles Boivin

Last modified: 11/07/95