Errors aren't that simple

cbuckley at vax1.tcd.ie cbuckley at vax1.tcd.ie
Fri Mar 9 22:57:35 AEST 1990


In article <Mar.7.10.43.42.1990.17402 at paul.rutgers.edu>, emuleomo at paul.rutgers.edu (Emuleomo) writes:

> Actually, I think the 'break' as used in the switch stmt was one of the few
> mistakes Dennis Ritchie made when designing the C language. By using
> 'break' both to end a 'case', and to exit a loop, he overloaded the meaning of
> 'break' and thus made it impossible to jump out of a switch that is embedded
> within a loop without using a flag or a GOTO!

I always thought "break" jumps out of the innermost construct - I presume you
mean that it is impossible to jump out of the loop as a result of one of the
cases in the switch() (which is imbdedded in the loop). At college, we're
taught that this is bad programming practice anyway! (Yes, yes, I *know* that
there are times when... etc... etc...)

> Was he trying to conserve keywords? In hindsight, I think 'endcase' would have 
> been a better choice.

However, I do kind of agree with this. It would make programs that bit easier
to read - especially as a "switch" cannot really be considered a loop, so it is
a bit peculiar to use a statement which implies "breaking" out of it.

> The other less serious flaw in C is the do...while contruct.
> I kind of prefer PASCAL's repeat....until construct myself.

How can this be a flaw? The two constructs are identical except for the fact
that the condition is reversed in do { } while();
If you *really* want a repeat{}until();, and you're not worried about using
#define to redefine language features (and no, I do *not* want to get back into
the "re: #define OR ||" argument over this), you can do :

#define repeat do
#define until(x) while(!(x))

*********NOTE - I would NEVER do this!!!!!!!***************
*********PLEASE do NOT send angry followups!***************
*********I KNOW it is unsound programming practice*********
*********I KNOW it defeats the compiler's error-trapping***

but this is really unnecessary, as do...while is just as flexible as
repeat...until - after all, every condition has a reverse.


exit(0);
Colm

+-----------------------------------------------------------------+
| Colm Buckley. (Computer Science, Trinity College, Dublin)       |
|                                                                 |
| EMAIL      : cbuckley at vax1.tcd.ie                               |
| Phone      : Dublin 770101                                      |
+---+---------------------------------------------------------+---+
    |       Beware of a programmer with a screwdriver...      |
    +---------------------------------------------------------+



More information about the Comp.lang.c mailing list