Go forward to For Statement.
Go backward to While Statement.
Go up to Statements.
The `do'-`while' Statement
==========================
The `do' loop is a variation of the `while' looping statement. The
`do' loop executes the BODY once, then repeats BODY as long as
CONDITION is true. It looks like this:
do
BODY
while (CONDITION)
Even if CONDITION is false at the start, BODY is executed at least
once (and only once, unless executing BODY makes CONDITION true).
Contrast this with the corresponding `while' statement:
while (CONDITION)
BODY
This statement does not execute BODY even once if CONDITION is false to
begin with.
Here is an example of a `do' statement:
awk '{ i = 1
do {
print $0
i++
} while (i <= 10)
}'
prints each input record ten times. It isn't a very realistic example,
since in this case an ordinary `while' would do just as well. But this
reflects actual experience; there is only occasionally a real use for a
`do' statement.