Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ncar!elroy.jpl.nasa.gov!jarthur!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: Is jumping inside loops legal? Message-ID: <375@taumet.com> Date: 3 Aug 90 18:27:10 GMT References: <746@ria.ccs.uwo.ca> Organization: Taumetric Corporation, San Diego Lines: 29 pruss@ria.ccs.uwo.ca (A.R. Pruss) writes: >I am wondering whether it is legal to jump into a loop, either via >a direct goto, or via a switch-case construct. Perfectly legal in ANSI C, and there is an example comparable to yours (except for one point) in section 3.6.6.1 The goto statement. The point to watch is that the initializer of the for loop will not be executed when you jump into the middle, so if you have goto middle; for(i = 0; i < max; i++) { ... middle: ... } there is no telling how many iterations will be performed. "Legal" is not the same as "good", however, and such code is hard to read, hard to maintain, and may prevent a the compiler from generating good code. It is worth your time to study your algorithm and code it in a more straightforward way. When I encounter such code written by others, I usually find that recoding it without tricks results in source code that is shorter and easier to understand, and in object code which is smaller and faster. -- Steve Clamage, TauMetric Corp, steve@taumet.com