|
Here's an example
of the second type of repetition statement called do-while. This sample code
computes the sum of integers starting from 1 until the sum becomes greater
than 1,000,000. The main difference between the while and do-while is the
relative placement of the test. The test occurs before the loop body for the
while statement, and the text occurs after the loop body for the do-while
statement. Because of this characteristic, the loop body of a while statement
is executed 0 or more times, while the loop body of the do-while statement is
executed 1 or more times.
|