The Queen's University of Belfast
Parallel Computer Centre

[Next] [Previous] [Top]

Control statements


Control statements

Topics

Conditional statements

IF statement

IF construct

[name:] IF (expression) THEN

block

ENDIF [name]

[name:] IF (expression1) THEN

block1

ELSEIF (expression2) THEN [name]

block2

...

[ELSE [name]

block]

ENDIF [name]

REAL :: cost, discount

INTEGER :: n

...

IF ( n==1 ) THEN

discount = 0.0

ELSEIF ( n<=5 ) THEN

discount = 0.1

ELSEIF ( n>5 .AND. n<=10) THEN

discount = 0.15

ELSE

discount = 0.25

ENDIF

cost = cost-(cost*discount)

WRITE(*,*) `Invoice for', cost

CASE

[name:] SELECT CASE( expression )

CASE( value ) [name]

block

...

[CASE DEFAULT

block]

END SELECT [name]

value [,...] !single value(s)

min: !from min upward

:max !from max downward

min:max !between the limits

INTEGER :: month

season: SELECT CASE( month )

CASE(4,5)

WRITE(*,*) `Spring'

CASE(6,7)

WRITE(*,*) `Summer'

CASE(8:10)

WRITE(*,*) `Autumn'

CASE(11,1:3,12)

WRITE(*,*) `Winter'

CASE DEFAULT

WRITE(*,*) `not a month'

END SELCET season

Repetition

DO construct

[name:] DO count=start, stop [, step]

block

END DO [name]

DO loops

Count control clause

frist: DO some=1,5

... !some=1,2,3,4,5

END DO first

DO i=10,16,2

... !i=10,12,14,16

END DO

DO j=-7,4,3

... !j=-7,-4,-1,2

END DO

last: DO k=20,0,-5

... !k=20,15,10,5,0

END DO last

Transferring control

outer: DO

...

inner: DO k=1,5

IF ( a(k)==0 ) CYCLE

IF ( a(k)<0 ) EXIT outer

...

END DO inner

END DO outer

GOTO statement

Form

GOTO label

INTEGER :: x

...

IF ( x.LT.1 ) GOTO 10

...

10 x = 1


[Next] [Previous] [Top]
All documents are the responsibility of, and copyright, © their authors and do not represent the views of The Parallel Computer Centre, nor of The Queen's University of Belfast.
Maintained by Alan Rea, email A.Rea@qub.ac.uk
Generated with CERN WebMaker