The only alternative left to the programmer is to use a while loop, which may be as follows:
- This program highlights an important feature of while loops. When a sequence of data is being entered in succession, the first value is read in before the start of the loop. This is necessary in order that we have something to test in the condition at the start of the loop. Each succeeding data value is read in within the loop once the previous value has been processed. This will normally be at the end of the loop. If a programmer omits the data input inside the loop there is a very high risk that the programs execution will get stuck permanently within the loop since no new values will be read in and tested for the exit condition.
- In general, if the number of iterations of a loop as not known in advance, the while loop is more appropriate than the do while loop in most cases.