gotos

Michael T Sullivan sullivan at vsi.UUCP
Sat Apr 9 06:29:20 AEST 1988


In article <2556 at ttrdc.UUCP>, levy at ttrdc.UUCP (Daniel R. Levy) writes:
> I know this battle is an old chestnut, but for the record do you guys believe
> that superfluous flags and great big if-then statements are truly superior
> to the goto?  (And the break, which is a goto by another name.)  E.g.:
> 
> 	while (loopcond) {
> 		for (i=0; i<limit; i++)
> 			if (frob(i) == TRUE)
> 				goto loopagain;	/* nice and CLEAN!!! */
> 		...
> 		/* lots and lots of code over many pages */
> 		...
> loopagain:	;
> 	}

	while (loopcond)
	{
		flag = FALSE;
		for (i=0; i<limit; i++)
		{
			if (frob(i))
			{
				flag = TRUE;
				break;
			}
		}
		if (flag)
			continue;
		...
		/* lots and lots of code over many pages */
		...
	}

You don't have to spin your wheels in a for loop and you don't have to use
the goto.  I should think if you can avoid a goto, do it.  Some people
believe gotos are inherently not "nice and CLEAN!!!".  But as you say, this
is an old chestnut.

-- 
Michael Sullivan		{uunet|attmail}!vsi!sullivan
				sullivan at vsi.com
HE V MTL



More information about the Comp.lang.c mailing list