'goto" gone from computer languages or is it!

John Hogerhuis jhoger at gmail.com
Mon May 16 14:37:57 CDT 2005


On 5/16/05, Sean 'Captain Napalm' Conner <spc at conman.org> wrote:

>   I'd skip both the GOTO and the conditional and do it:
> 
>         void print_ary(int *aryp,size_t n)
>         {
>           size_t  i;
>           char   *sep;
> 
>           assert(aryp != NULL);         /* sorry, gotta check */
>           assert(n    > 0);
> 
>           for (i = 0 , sep = "" ; i < n ; aryp++ , i++)
>           {
>             printf("%s%u",sep,&aryp);
>             sep = ",";
>           }
>           putchar('\n');
>         }
> 
>   -spc (Who tries to avoid conditionals when possible ... )
> 
> 

Clever. I don't like the conditional either, but you are also
unnecessarily reinitializing sep every time through the loop. With the
goto I avoid both the conditional and the reinit.

In a way I guess I'm creating a new control structure (at least new to
me). Heck maybe I'll add it as a full bonified control structure in my
WP-2 Forth. Forth doesn't have goto, but it gives you the tools to
create your own control structures, so a good trade-off.

BTW, I think you mean *aryp  not &aryp

-- John.



More information about the cctalk mailing list