File: gawk.info, Node: Do Statement, Next: For Statement, Prev: While Statement, Up: Statements 7.4.3 The 'do'-'while' Statement -------------------------------- The 'do' loop is a variation of the 'while' looping statement. The 'do' loop executes the BODY once and then repeats the BODY as long as the CONDITION is true. It looks like this: do BODY while (CONDITION) Even if the CONDITION is false at the start, the BODY executes 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 the BODY even once if the CONDITION is false to begin with. The following is an example of a 'do' statement: { i = 1 do { print $0 i++ } while (i <= 10) } This program prints each input record 10 times. However, it isn't a very realistic example, because in this case an ordinary 'while' would do just as well. This situation reflects actual experience; only occasionally is there a real use for a 'do' statement.