and while loops
(I rarely use for's), but C really suffers from a lack of
a general error trapping mechanism that one can invoke to break out of
loops as required. Sometimes I think goto's are the answer but I can
never find an appropriate way to implement it.
errflag := 0 /* is it := in C to assign a value? */
No. That's BLISS and BCPL, among others, IIRC. Drop the colon
DO WHILE variable < end AND errflag = 0 {
do stuff
variable++ /* I think that increments a variable */
Yes.
IF error THEN
errflag := 1
ENDIF
LOOP
IF errflag = 1 THEN
do error processing
ENDIF
No, I'm not a C programmer (nor do I play one on TV).
Well... being a "perfessional", let me try...
Here's one way to do it that I have personally used:
if (my_function())
do error processing
my_function()
{
/* I prefer for to while. It's all right here to see and debug */
for (variable=0; variable < end; variable++) {
do some work
if (some error thing)
return 1;
}
return 0;
}
If you insist on keeping the code in the higher-level function, there's
always the "break" statement.
In 15 years of C programming, I have yet to use a single goto. Yes, it
can simplify exception processing, but I've always found that if you
need a goto to simplify things, you didn't design it well enough the
first time around.
-ethan