Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site allegra.UUCP Path: utzoo!linus!philabs!seismo!harpo!eagle!allegra!alan From: alan@allegra.UUCP Newsgroups: net.lang.c Subject: Unnecessary Goto's Message-ID: <2028@allegra.UUCP> Date: Tue, 22-Nov-83 12:56:47 EST Article-I.D.: allegra.2028 Posted: Tue Nov 22 12:56:47 1983 Date-Received: Fri, 25-Nov-83 03:52:32 EST Organization: AT&T Bell Laboratories, Murray Hill Lines: 33 I recently had occasion to use a construct which is a little strange, and I was wondering whether it's guaranteed to be portable. if(0) retry: printf("Try again.\n"); printf("What's two plus two? "); .... /* if get a bad answer */ goto retry; This code ensures that the "Try again" message isn't executed the first time through. It works fine on the VAX (4.1bsd) and PDP-11 (v7). Can I be sure that the "goto" to a statement within a condition will work with any C compiler? Dave Sherman Beside the portability issue, there is the issue of clarity here. do { printf("What's two plus two? "); ... if ( /* bad answer */ ) printf("Try again.\n"); } while ( /* bad answer */ ); Now, isn't that much clearer? Alan S. Driscoll AT&T Bell Laboratories