go to previous page   go to home page   go to next page

Answer:

Yes, although this is not as clear as the first method.


Sentinel Loop

Anything that can be done with looping can be done with recursion. So there is a recursive equivalent of a sentinel-controlled loop. Here is one way to do this:

  1. If the current value is the sentinel value, finish the task.
  2. Otherwise, get the next data value.

The data values might come from a file or from user input. The recursive method would call itself for each new value. But this is not a natural fit to how reading from a file should be done. The usual iterative way is a more natural way to think of the problem, and is what you would ordinarily use.


QUESTION 13:

Could a sentinel value arise as a result of computation?


go to previous page   go to home page   go to next page