"C" wish list.
cjl at iuvax.UUCP
cjl at iuvax.UUCP
Sun Oct 27 02:55:00 AEST 1985
I would like to see a loop-exit statement added to replace the break
statement. For example a loop with multi-exit points should not pretend
to be a "for" loop like :
for (i=0; i<100; i++) {
/* IN NATURAL LANG, THIS MEANS THE LOOP HAS A SIMPLE EXIT POINT,
-- AND WILL ITERATE EXACTLY 100 TIMES. */
checkReturn = function1(x);
if (checkReturn == BAD) break;
/* THE BREAK STATEMENT HERE FUNCTIONS LIKE GOTO AND DESTROYS
-- THE ORIGINAL, SIMPLE MEANING OF FOR STATEMENT. */
......
checkReturn = function5(x);
if (checkReturn == BAD)
result[i] = 0;
else
result[i] = function6(x);
}
With loop-exit statement, the reader is warned explicitly the
existence of multi-exit ( or break) points inside the loop.
i = 0;
loop {
/* WHENEVER WE SEE A LOOP STATEMENT, WE KNOW THERE MAY HAVE
-- SEVERAL EXIT POINTS. IT IS NOT AN EASY LOOP. */
if (i>=100) then exit;
/* NOW YOU DON'T HAVE THE IMPRESSION THAT THE LOOP
-- WILL ALWAYS ITERATE 100 TIMES BECAUSE THERE MAY EXIST
-- OTHER EXIT POINTS. */
checkReturn = function1(x);
if (checkReturn == BAD) exit;
.................
checkReturn = function5(x);
if (checkReturn == BAD)
result[i] = 0;
else
result[i] = function6(x);
i++;
}
This is a style encouraged by Ada or Modula-2 language.
In existing C language, we may use macro definitions to simulate
the loop-exit statement as :
define loop for(,,)
define exit break
C.J.Lo
Dept. of CIS, IUPUI
ARPA : cjl at Indiana@CSNet-Relay
UUCP : ...!iuvax!cjl
More information about the Comp.lang.c
mailing list