Page 1 of 1

Exit mid-loop

Posted: Fri Apr 01, 2011 12:15 pm
by Helpdesk
What is the 'correct' way to exit a REPEAT...UNTIL loop?

Code: Select all

REPEAT
  ...
  ...
  IF Error THEN exit;    (* Leave the room NOW!! *)
  ....
  ....
UNTIL ...
Not appropriate to check at the beginning of the loop as Error hasn't yet
occurred.
Can't continue with the loop to UNTIL as I have an Error.

Re: Exit mid-loop

Posted: Fri Apr 01, 2011 12:43 pm
by cfbsoftware

Code: Select all

  REPEAT
    ...
    IF ~error THEN
      ...
    END
  UNTIL ... OR error;

Re: Exit mid-loop

Posted: Wed Sep 14, 2011 11:47 am
by Eugene Temirgaleev
Helpdesk wrote:What is the 'correct' way to exit a REPEAT...UNTIL loop?
The truly correct way is try to express your algorithm in the form which isn't require mid-exit loops. This is possible & lead to more clearly programs in most cases. Prof Wirth removed LOOP/EXIT statements in the Revised Oberon (Oberon-07) to encourage this way.

You can see some conversions of mid-exit loops here.