Answer
- Think of the function that we wrote a few lessons back to
approximate the square root of a number. That program consisted of a
loop that computed successively better approximations to the square
root of some number. In that case, we want to stop approximating when
we get an answer that is close enough to the true square root to suit
us. And we can't tell in advance how many iterations that might take.
- Imagine writing a function that takes an array and a number as
arguments, and returns an index into the array where the number is
stored. The best way to implement this is by using a loop to iterate
through the array until the desired element is found. If we are using
a plain DO loop, we'll have to continue with the loop even if the
desired number is found in the first iteration. We'd prefer to
stop the loop as soon as the desired number is found.
Return to lesson.