Re: goto considered essential
- Posted by Jason Gade <jaygade at yahoo.com> Jan 21, 2006
- 509 views
Tom Dailey wrote: > > > John: > > The mechanism you propose sounds like a somewhat less > restricted version of what I was proposing in my final > code fragment. In fact, my C code looks just like what > you've described your friend writing, except my "egress" > is named "return_point", and what you find there is > typically "return rv;", or, for boolean functions, > "return answer;". > > I think we're on the same page here. > > Tom According to "best practices", every function should have one entrance and one exit. But I think you can have either multiple return statements or a goto. I don't think there is a middle ground here. Just the nature of the beast. I guess you could wrap the entire thing in a while loop and use exit...
while 1 do -- some stuff if condition1 then -- do some condition one stuff exit elsif condition2 then -- do some condition two stuff exit -- etcetera end if end while return result
But that would break if you tried to exit out of more than one level of loop. You would have to set a flag variable. -- "The author regrets that he is unable to reconcile himself to the thoughtful point of view you have expressed. However, it must be kept in mind that being raised in different cultures and different places can result in such differences of viewpoint between individuals. The author is from planet Earth." [author unknown] j.