goto jumps into loops

John Owens jso at edison.UUCP
Wed Apr 30 05:54:02 AEST 1986


In respose to the program by
> 	Dave Harmon
> 	dmh at mit-borax.arpa
> 	dmh at borax.lcs.mit.edu
where he asks for a way to avoid a goto in his loop (translated from Pascal).


How about something like.....


#include <stdio.h>
#include "/usr/dmh/nastydefs"
#define MAX NUM_KEYWORDS   /*The highest element in use by the application*/

wrtlist (listp)
set *listp;
{
  unsigned char i;
  set list;

  list = *listp;
  for (i=0; i <= MAX; i++) {
    if (in(i,&list)) {
	unsigned char save_i;
	printf(" %d",i);
	save_i = i;
	while (++i <= MAX && in(i,&list))
		;
	if (i > save_i + 1)
		printf("-%d",i-1);
	/* doesn't matter that we'll i++ here, since we know !in(i,&list) */
    }
  }
  printf("\n");
  return(0);
}


[No guarantees, but you get the idea.]

			   John Owens
	    edison!jso%virginia at CSNet-Relay.ARPA
General Electric Company		Phone:	(804) 978-5726
Factory Automation Products Division	Compuserve: 76317,2354
	       houxm!burl!icase!uvacs
...!{	       decvax!mcnc!ncsu!uvacs	}!edison!jso
		 gatech!allegra!uvacs



More information about the Comp.lang.c mailing list