'goto" gone from computer languages or is it!

Jules Richardson julesrichardsonuk at yahoo.co.uk
Mon May 16 17:04:09 CDT 2005


On Mon, 2005-05-16 at 14:33 -0700, John Hogerhuis wrote:
> On 5/16/05, Dave Dunfield <dave04a at dunfield.com> wrote:
> > Given that the original example assumes n > 0 (the test is skipped on
> > first entry to the loop), you can accomplish this function with neither
> > an extra conditional, superfluous assignment, extra variables or use
> > of 'goto'
> > 
> > void print_arg(int *aryp, unsigned n)
> > {
> >    int i;
> >    for(i=0; ;) {
> >       printf("%u", aryp[i]);
> >       if(++i >= n)
> >          break;
> >       fputs(", ", stdout); }
> >    putc('\n', stdout);
> > }
> 
> Now that's a right answer.

... the wrong answer being to dump out each array element followed by a
comma, then output ^H as the final step in the function ;-)

Real Programmers would presumably use putc exclusively in favour of the
more computationally expensive printf...

cheers

J.



More information about the cctalk mailing list