Previous: if-else, Up: Conditionals and Loops


5.20.3 while

gtroff provides a looping construct using the while request, which is used much like the if (and related) requests.

— Request: .while expr anything

Evaluate the expression expr, and repeatedly execute anything (the remainder of the line) until expr evaluates to 0.

          
          .nr a 0 1
          .while (\na < 9) \{\
          \n+a,
          .\}
          \n+a
              ⇒ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Some remarks.

— Request: .break

Break out of a while loop. Be sure not to confuse this with the br request (causing a line break).

— Request: .continue

Finish the current iteration of a while loop, immediately restarting the next iteration.

See Expressions.