Some interesting novice questions from a novice guy

Rahul Dhesi dhesi%cirrusl at oliveb.ATC.olivetti.com
Sat Oct 27 14:24:32 AEST 1990


In <L3O6IN7 at xds13.ferranti.com> peter at ficc.ferranti.com (Peter da Silva) writes:

>	while(*foo++)
>		continue;

I know I'm not a C guru, and maybe I'm the only one here who gets
confused by autoincrement-right-after-dereferencing, but I have always
hated that "continue" statement, because it bothers my intuition.  I
have always been taught that "continue" means "That's all right, don't
mind me, just keep on doing what you were doing before I interrupted
you."  But the C meaning of "continue" (not to be confused with the
Fortran meaning of "CONTINUE") is more like: "Hey you!  Just what the
heck do you think you are doing?  Stop that right now!  Go back to the
beginning and do it all over again, and try to do it right this time!"

When I see "continue" in the middle of a long loop, I get a little
confused, but I usually recover.  But to see "continue" as the only
thing in a loop really stupifies me.  Consider:

	while(*foo++) {
           Hey you!  Just what the heck do you think you are
           doing?  Stop that right now!  Go back to the
           beginning and do it all over again, and try to do
           it right this time!
        }

I guess part of the problem is the cognitive dissonance (Hah!  I bet
you thought I didn't know anything about music!) that I go through when
I see a C "continue" used in the Fortran sense;  for what the
programmer was *really* trying to say was:

	while(*foo++)		/* very C-ish */
           keep on going;	/* very Fortran-ish */

The confusion just doesn't cut it for me.  So I do the good old simple
stuff, complete with comments that a real guru wouldn't need (but I
do):

        while (*foo != '\0')	/* find trailing null */
           foo++;
        foo++;			/* go past it */

(Actually, when I have to skip the rest of the loop body, more often
than not, I put a label near the end of the loop and do a goto to it.
This way I can search for all occurrences of goto's to that label, and
they are usually unique for a given loop.  A search for "continue", if
I used it, would probably occur in many unrelated places in any given
file, and I would be even more confused than I am now.)
--
Rahul Dhesi <dhesi%cirrusl at oliveb.ATC.olivetti.com>
UUCP:  oliveb!cirrusl!dhesi
A pointer is not an address.  It is a way of finding an address. -- me



More information about the Comp.lang.c mailing list