views:

14

answers:

0

What is the most appropriate sentinel method?

This breaks out of an infinite loop:

infinite loop
      read in a value;
      if (value == Sentinel) then exit;
      process the value;

This uses duplicate code:

read in a value;
while (value != Sentinel)
      process the value;
      read in a value;

This uses a boolean variable instead of an infinite loop:

while (boolean)
      read in a value;
      if (value == Sentinel) then
          boolean = false;
      else
          process the value;

Are there other sentinel methods that are better than these?

Some people don't like breaking out of infinite loops. Some people don't like duplicate code.

What should I do?