Chapters:
1: Introduction
2: Simple example
3: Invocation
4: Finer Control
5: X-Y Plots
6: Contour Plots
7: Image Plots
8: Examples
9: Gri Commands
10: Programming
11: Environment
12: Emacs Mode
13: History
14: Installation
15: Gri Bugs
16: Test Suite
17: Gri in Press
18: Acknowledgments
19: License
Indices:
Concepts
Commands
Variables

### 9.3.52: ``while`'

    `while .test.|{rpn ...}'

Perform statements in loop while the value of ``.test.`' or the RPN expression is nonzero. The end of the loop designated by a line containing the words ``end while`'. The value ``.test.`' may be an rpn expression. To leave the loop prematurely, use a ``break`' statement. Upon encountering a ``break`' statement, Gri jumps to the line immediately following the loop. If the ``-chatty`' option is nonzero, a notification is printed every 1000 passes through the loop, as a debugging measure to catch unintended infinite loops.

Examples:

- Loop forever, printing a message over and over.

      while 1
        show "This loops forever. Need to 'break'"
      end while

- Read number pairs from a file, plotting bullets at the indicated locations. Note the use of an infinite loop, with a break condition following an end-of-file test. (Do not be tempted to write such loops as ``while !..eof..`' because that would not catch the end of file until the next time through the loop. The result would be to draw the last bullet twice, since the ``read`' will not update the variables when the end of file is encountered.)

      while 1
        read .x. .y.
        if ..eof..
          break
        end if
        draw symbol bullet at .x. .y.
      end while

- Loop 10 times, printing the values of ``.i.`' as they range 0, 1, ..., 9. After exiting from the loop, ``.i.`' will equal 10. Be careful to use the correct rpn greater-than test to avoid an infinite loop.

      .i. = 0
      while {rpn .i. 10 >}
        show .i.
        .i. += 1
      end while