
PROGRAM do_loop_5
	IMPLICIT NONE

	! This program demonstrates a `do loop'. Repetition (rapidly and on a 
	! large scale) is one of the main advantages of the computer. 

	! declarations
	INTEGER :: i
	REAL    :: x,y,sum
	REAL, INTRINSIC :: ATAN

	! summing an infinite number of terms gives pi.
	sum = 1.0
	DO i = 1,100
		sum = sum + (-1)**i/(2.0*i+1)	! note the indentation.
	END DO
	
	! note that `=' is an assignment operation and is distinct from the
	! mathematical `='.
	sum = 4.0*sum

	!outputs
	PRINT *, 'The series sum is ',sum
	PRINT *
	PRINT *, 'The exact value of pi is ', 4.0*ATAN(1.0)

END PROGRAM do_loop_5
