24.11.2014 Views

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

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.

<strong>Language</strong> <strong>Reference</strong><br />

2.24 ELSE Statement<br />

<br />

ELSE<br />

The ELSE statement is used in conjunction with the IF or ELSE IF statement. The range of the ELSE<br />

block is terminated by a matching END IF statement.<br />

Example:<br />

IF( A .LT. B )THEN<br />

PRINT *, ’A is less than B’<br />

ELSE<br />

PRINT *, ’A is greater than or equal to B’<br />

END IF<br />

Transfer of control into the range of an ELSE block is illegal. It is interesting to note that the ELSE<br />

statement may be identified by a statement label but it must not be referenced by any statement!<br />

Example:<br />

* Illegal branch to a labelled ELSE statement.<br />

IF( A .LT. B )THEN<br />

PRINT *, ’A is less than B’<br />

100 ELSE<br />

PRINT *, ’A is greater than or equal to B’<br />

GO TO 100<br />

END IF<br />

The above is an example of an illegal way to construct an infinitely repeating loop. The following is the<br />

correct way to do this.<br />

Example:<br />

IF( A .LT. B )THEN<br />

PRINT *, ’A is less than B’<br />

ELSE<br />

100 PRINT *, ’A is greater than or equal to B’<br />

GO TO 100<br />

END IF<br />

For more information, see the chapter entitled "Program Structure Control Statements" on page 193.<br />

54 ELSE Statement

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

Saved successfully!

Ooh no, something went wrong!