Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!samsung!brutus.cs.uiuc.edu!psuvax1!news From: flee@shire.cs.psu.edu (Felix Lee) Newsgroups: comp.lang.misc Subject: Breaking loops (Re: Anyone want to design a language?) Message-ID: Date: 20 Feb 90 15:48:51 GMT References: <22569:05:10:24@stealth.acf.nyu.edu> <8475@wpi.wpi.edu> <4489:05:14:19@stealth.acf.nyu.edu> <10790@june.cs.washington.edu> Sender: news@cs.psu.edu (Usenet) Distribution: usa Organization: Penn State University Computer Science Lines: 25 Scott MacHaffie wrote: >Unconditional loops have a serious problem: you have to read all of the >code inside the loop to find out when (or if) it terminates. Well, not if you undent the terminating conditions properly: loop do_stuff(); break cleanup() when (done); do_more_stuff(); end loop; Unfortunately this isn't convenient in most languages. C doesn't have an inverted if statement, so undenting is confusing: for (;;) { do_stuff(); if (done) { cleanup(); break; } do_more_stuff(); } The last brace looks like it closes the if statement. I usually just mark break statements with a /*BREAK*/ off to the right somewhere. Ada has "EXIT loop WHEN condition;" which you can undent, but doesn't provide for a cleanup clause. But you often don't need one anyway. -- Felix Lee flee@shire.cs.psu.edu *!psuvax1!flee