25.06.2013 Views

Il Linguaggio Fortran 90/95

Il Linguaggio Fortran 90/95

Il Linguaggio Fortran 90/95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2.2 Istruzioni di diramazione 99<br />

END SELECT<br />

END PROGRAM demo_CASE<br />

Analogamente è possibile inserire uno o più costrutti IF (eventualmente innestati) all’interno<br />

di un costrutto SELECT CASE, come dimostra il seguente esempio:<br />

PROGRAM giorni<br />

! Scopo: Fornisce il numero di giorni presenti in un mese<br />

IMPLICIT NONE<br />

INTEGER :: month, year, ndays<br />

! start<br />

WRITE(*,*) " Inserisci l’anno: "<br />

READ(*,*) year<br />

WRITE(*,*) " Inserisci il mese: "<br />

READ(*,*) month<br />

SELECT CASE(month)<br />

CASE(11,4,6,9) ! 30 gg a Nov con Apr, Giu e Set...<br />

ndays = 30<br />

CASE(2) ! ...di 28 ce n’e’ uno...<br />

IF(MODULO(year,4)==0) THEN<br />

ndays = 29 ! (anno bisestile)<br />

ELSE<br />

ndays = 28 ! (anno non bisestile)<br />

END IF<br />

CASE DEFAULT ! ...tutti gli altri ne han 31<br />

ndays = 31<br />

END SELECT<br />

WRITE(*,*) " <strong>Il</strong> numero di giorni del mese no. ", month, " e’: ", ndays<br />

STOP<br />

END PROGRAM giorni<br />

2.2.3 L’istruzione GOTO<br />

L’istruzione di salto incondizionato GOTO è un’istruzione di diramazione che può essere utilizzata<br />

per trasferire il controllo ad un punto ben preciso del programma. Essa si presenta nella forma:<br />

GOTO etichetta<br />

In altre parole l’istruzione GOTO trasferisce il controllo del programma all’istruzione caratterizzata<br />

da etichetta. Ad esempio:<br />

IF(x

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!