Exit mid-loop

Topics related to the use of Oberon language features
Locked
Helpdesk
Posts: 33
Joined: Sat Jan 01, 2011 5:43 am
Contact:

Exit mid-loop

Post by Helpdesk » Fri Apr 01, 2011 12:15 pm

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.

cfbsoftware
Site Admin
Posts: 493
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: Exit mid-loop

Post by cfbsoftware » Fri Apr 01, 2011 12:43 pm

Code: Select all

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

Eugene Temirgaleev
Posts: 3
Joined: Wed Sep 14, 2011 11:19 am
Location: Russia, Orel
Contact:

Re: Exit mid-loop

Post by Eugene Temirgaleev » Wed Sep 14, 2011 11:47 am

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.

Locked