loops in c

Lucio de Re lucio at proxima.UUCP
Sat Apr 7 22:38:20 AEST 1990


In article <1546 at amethyst.math.arizona.edu> raw at 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 at proxima
                Disclaimer: I hope he was joking!



More information about the Comp.lang.c mailing list