Continue problem?

Jim ix269 at sdcc6.UUCP
Wed Sep 5 10:26:12 AEST 1984


()
	I ran into this while writing a parser (sp?) and am not sure
    where to attribute the error, could just be something I don't
    understand about continue.  I believed it to mean "jump down the
    the bottom of the loop", but it seems to mean here to jump down
    to the last line in the loop as if it where in the "for" statement.
    This could be just a 4.2bsd compiler *joy* but if it is an error,
    get out your flamethrowers I be ready to be a learn'n sumtin' B->

+---------------+
| the buggy one |
+---------------+
#include <stdio.h>

#define ORTHREE(a,x,y,z)	(a == x || a == y || a == z)

char buf[BUFSIZ] = "(this()\"is the unit\")\n";

main()
{
int cnt;
char *cp;
extern char buf[];

cp = &buf[0];

    for(cnt = 0 ; cnt > 0 || ORTHREE(*cp,'(',')','\"') ;) {
	switch (*cp++) {
	    case '(':
		cnt++;
		continue;
	    case ')':
		cnt--;
		continue;
	    case '\"':
		while (*cp != '\"' && *cp != '\n')
		    cp++;
		if (*cp == '\"') {
		    cp++;
		    continue;
		}
		else 
		    break;/* quit out of for loop */
	}/* end switch */
	break;	/* will break out with cnt > 0 */
    }/* end for */

    printf("cnt = %d\n",cnt);
    printf("cp = %s",cp);
    printf("buf = %s",&buf[0]);
}
+--------------+
|    Output    |	
+--------------+
cnt = 1
cp = his()"is the unit")
buf = (this()"is the unit")

what I expected was (which comes from the next one):

cnt = 0
cp =
buf = (this()"is the unit")
+--------------+
| kind program |
+--------------+
#include <stdio.h>

#define ORTHREE(a,x,y,z)	(a == x || a == y || a == z)

char buf[BUFSIZ] = "(this()\"is the unit\")\n";

main()
{
int cnt;
char *cp;
extern char buf[];

cp = &buf[0];

    for(cnt = 0 ; cnt > 0 || ORTHREE(*cp,'(',')','\"') ;) {
	switch (*cp++) {
	    case '(':
		cnt++;
		continue;
	    case ')':
		cnt--;
		continue;
	    case '\"':
		while (*cp != '\"' && *cp != '\n')
		    cp++;
		if (*cp == '\"') {
		    cp++;
		    continue;
		}
		else 
		    break;/* quit out of for loop */
	}/* end switch */
	if (*cp == '\n') break;	/* will be ok */
    }/* end for */

    printf("cnt = %d\n",cnt);
    printf("cp = %s",cp);
    printf("buf = %s",&buf[0]);
}
----------------- cut -------------

	Does anyone have a different idea on this???


				Jim.

				{dcdwest,ucbvax}sdcsvax!sdccs6!ix269

				(just a number or has it some semantic value?)



More information about the Comp.lang.c mailing list