Welcome to AE Resources
Converted document Converted document

FORTRAN 90+: DO LOOP DEMONSTRATION

It is recommended to look at the numerical methods codes where the use of loops is demonstrated. Some additional examples of loops using code snippets are included here.
EXAMPLE: STANDARD DO LOOPS
DO j = 5, 1, -1  !From highest to lowest
		DO i = 1,(6-j),2  ! Skip every other point
			md(i, j) = md(i+1, j-1) - md(i, j-1)
		ENDDO
ENDDO
EXAMPLE: WHILE LOOPS
PROGRAM HelloGoodbye
IMPLICIT NONE
INTEGER :: input
input=0
	DO WHILE(input/=1 .and. input/=2)
		PRINT *, "Enter 1 or 2"
		READ(*,*) input
	END DO
	
	IF (input==1) THEN
		PRINT *, "Hello World!"
	ELSE IF (input==2) THEN
		PRINT *, "Goodbye World!"
	END IF
END PROGRAM HelloGoodbye