Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
DO WHILE
◄Up► ◄Contents► ◄Index► ◄Back►
─────DO WHILE───────────────────────────────────────────────────────────────
Action
Executes a block of statements repeatedly while a logical condition
remains true.
Syntax
DO [label [, ] ] WHILE (logicalexpr)
Parameter Description
label A label for an executable statement or a
CONTINUE statement
logicalexpr A test expression that evaluates to true or
false
Remarks
If <label> is used, the loop terminates with the labeled statement.
If not used, the loop terminates with an END DO statement.
A terminating statement must follow the DO WHILE statement and be
in the same program unit. This statement must not be an
unconditional or assigned GOTO, a block or arithmetic IF, CASE,
CYCLE, DO, ELSE, ELSE IF, END, END IF, END SELECT CASE, EXIT,
RETURN, SELECT CASE, or STOP statement.
Execution of a CALL statement that is in the range of a DO WHILE
loop does not terminate the DO WHILE loop unless an alternate-
return specifier in a CALL statement returns control to a
statement outside the DO WHILE loop.
The following restrictions apply:
■ If a DO WHILE loop appears within another DO or DO WHILE
loop, its range must be entirely within the range of the
enclosing loop.
■ Two or more DO or DO WHILE loops may share one labeled
terminal statement. An END DO statement may terminate only
one DO or DO WHILE loop.
■ If a DO WHILE statement appears within an IF, ELSE IF, or
ELSE block, the range of the DO WHILE loop must be entirely
within the block.
■ If a block IF statement appears within a DO WHILE loop, its
associated END IF statement must also be within that DO WHILE
loop.
■ If a SELECT CASE statement appears within the range of a
DO WHILE loop, its associated END SELECT CASE statement must
also be within that DO WHILE loop.
■ Jumping into the range of a DO WHILE loop is not permitted.
See Also: ◄$DO66►
Example
CHARACTER*1 input
input = ' '
DO WHILE ((input .NE. 'n') .AND. (input .NE. 'y'))
WRITE (*, '(A)') 'Enter y or n: '
READ (*, '(A)') input
END DO
-♦-