02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Control constructs and statement blocks<br />

Execution control<br />

Control constructs and statement blocks<br />

A control construct consists of a statement block whose execution logic is defined by one of the<br />

following control statements:<br />

CASE statement<br />

DO statement<br />

IF statement<br />

A statement block is a sequence of statements delimited by a control statements and its<br />

corresponding terminal statement. A statement block consists of zero or more statements and<br />

can include nested control constructs. However, any nested construct must have its beginning<br />

and end within the same statement block.<br />

Although the Standard forbids transferring control into a statement block except by means of<br />

its control statement, <strong>HP</strong> <strong>Fortran</strong> allows it. The Standard does permit the transferring control<br />

out of a statement block. For example, the following IF construct contains a GO TO statement<br />

that legally transfers control to a label that is defined outside the IF construct:<br />

IF (var > 1) THEN<br />

var1 = 1<br />

ELSE<br />

GO TO 2<br />

END IF<br />

...<br />

2 var1 = var2<br />

The next logical IF statement is nonstandard (but permitted by <strong>HP</strong> <strong>Fortran</strong>) because it would<br />

transfer control into the DO construct:<br />

IF (.NOT.done) GO TO 4 ! nonstandard!<br />

...<br />

DO i = 1, 100<br />

sum = b + c<br />

4 b = b + 1<br />

END DO<br />

The following sections describe the operations performed by the three control constructs.<br />

CASE construct<br />

The CASE construct selects (at most) one out of a number of statement blocks for execution.<br />

Chapter 6 105

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

Saved successfully!

Ooh no, something went wrong!