!------------------------------------------------------------------------------
!
!  Program name:
!
!    square_sum
!
!  Purpose:
!   
!    This program contains a DO construct which reads numbers from
!    the data file square.dat, skips negative numbers (use CYCLE), 
!    adds the square root of positive numbers, and concludes if 
!    the present number is zero (use EXIT).
!
!------------------------------------------------------------------------------

PROGRAM square_sum

  IMPLICIT NONE
  REAL sq_sum, number
 
  OPEN (1, FILE = 'square.dat')     ! open data file containing numbers

  sq_sum = 0.0                      ! preset sq_sum as 0

  DO 
    READ (1, '(F4.2)') number       ! read number from the data file
    WRITE (*, *) 'number = ', number 	
    IF (number == 0.0) EXIT         ! exit if present number is 0
    IF (number <  0.0) CYCLE        ! skip the negative number
    sq_sum = sq_sum + SQRT(number)  ! add the square root  
    WRITE (*,*) 'square_sum =', sq_sum
  END DO

  PRINT '(/)'
  PRINT *,'The solution is:'
  WRITE (*,*) sq_sum

END PROGRAM square_sum

