gotos

00704a-Liber nevin1 at ihlpf.ATT.COM
Sat Apr 9 05:39:37 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:	;
|	}

Opinion:  this is an example of FORTRAN disguised as C.

|versus

|	while (loopcond) {
|		boolean_flag=FALSE;
|		for (i=0; i<limit; i++) {
|			if (boolean_flag == TRUE) {
|				;	/* spin uselessly */
|			} else if (frob(i) == TRUE) {
|				boolean_flag=TRUE;
|			}
|		}
|		if (boolean_flag==FALSE) {
|			...
|			/* lots and lots of code over many pages */
|			...
|		}
|	}

Opinion:  this is an example of Pascal disguised as C.


For the record:  these are BOTH bad C programming paradigms!!  There are
other constructs which can alter the flow of control:  break, continue, and
return.  Use them!!  In this particular case, using a continue statement
inside in your Fortran-type example instead of a goto is much more preferable.
-- 
 _ __			NEVIN J. LIBER	..!ihnp4!ihlpf!nevin1	(312) 510-6194
' )  )				"The secret compartment of my ring I fill
 /  / _ , __o  ____		 with an Underdog super-energy pill."
/  (_</_\/ <__/ / <_	These are solely MY opinions, not AT&T's, blah blah blah



More information about the Comp.lang.c mailing list