Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!umich!yale!think!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!nic.MR.NET!shamash!tank!gargoyle!ddsw1!olsa99!oct1!proxima!lucio From: lucio@proxima.UUCP (Lucio de Re) Newsgroups: comp.lang.c Subject: Re: loops in c Message-ID: <1274@proxima.UUCP> Date: 7 Apr 90 12:38:20 GMT References: <1546@amethyst.math.arizona.edu> Reply-To: lucio@proxima.UUCP (Lucio de Re) Organization: FLAGSHIP Wide Area Networks - Cape Town Lines: 58 In article <1546@amethyst.math.arizona.edu> raw@math.arizona.edu writes: > >So lets make it easier on all. Demand a loop {stmnt} test {stmnt} repeat >in ANSI C!!!!!!!!!!!!!!!!!!!!!!!!!!! > > Richard Walter Funny, I've never used a LOOP .. EXIT construct, not even in those PASCAL days when it was (sometimes) available. Firstly, I don't like looking for the exit from a loop construct; secondly it allows multiple exits, which run counter to my structured programming orientation and thirdly, as I said, it's unnecessary, at least to me; I have written a lot of code and I am not embarrassed to set a condition variable to tell me whether the loop should be repeated or terminated, nor is the ineffi- ciency (space only, for that matter) of a preliminary loop execution likely to cause me to lose any sleep. A friend who thinks efficiency comes foremost was puzzled by the following COBOL excerpt: PERFORM READREC. PERFORM READREC UNTIL ZEOF. where READREC. READ REC AT END set ZEOF conditional. (An abbreviation; what need I say, I gave up COBOL whenever I could.) I felt it was rather elegant (if it can be called that!) and the space inefficiency was minute. For those who don't know COBOL, the UNTIL clause is tested at the BEGINNING of the loop, while a plain PERFORM executes once only. Also, I _have_ used for(;;) which my personal "util.h" defines: #define forever for(;;) where I don't expect the loop to terminate except when the power switch is used. No breaks in those loops. Fussy, yes; I also don't use do {} while () except when pushed (and against my better judgement) because in FORTRAN the default execution of loops at least once gave me lots of headaches I have no intention of repeating and seldom even exit() from a program except at the end, at the cost of additional nesting (I'd love a 132 column screen). So that's my buzz. Anybody out there feels the way I do? Anybody out there has read "A Discipline of Programming" by Dijkstra and would like to compare (C) notes? ---------------------------------------------------------------------- I used to design nuclear reactors and you should see the code that engineers and scientists come up with. Yuuuck! Spaghetti everywhere. -------------------------------------------------- (Kenneth L Moore) - Lucio de Re ...uunet!ddsw1!olsa99!proxima!lucio -------------------------------------------------------- lucio@proxima Disclaimer: I hope he was joking!