C++ tutorial: do


The 'do' loop is always executed at least once
The basic structure of the do...while loop is as follows:

do
     {
     statment1;
     statment2;
	// more statements...
     } while (condition)

It works in much the same way as the 'while' loop, except that the test is at the end of the loop, not the start. In my experience, the do...while loop is used less often that the 'while' and 'for' loops. However, it is the natural loop to use when the 'condition' depends on the result of some calculation performed inside the loop.

©1994-2003 Kevin Boone, all rights reserved