Gri Commands

1: Introduction
2: Simple example
3: Fancy example
4: Running Gri
5: Programming Gri
6: General Issues
7: X-Y Plots
8: Contour Plots
9: Image Plots
10: Examples
11: Handling Data
12: Gri Commands
13: Gri Extras
14: Evolution of Gri
15: Installing Gri
16: Gri Bugs
17: System Tools
18: Acknowledgments
19: License
20: Newsgroup

21: Concept Index

12.49: The `while' Command

`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
    

  • Repeatedly read two numbers, and plot a bullet at the indicated location. If (or, hopefully, ``when'') the end of the file is encountered, break out of the loop; otherwise continue plotting forever.
    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