Re: goto considered essential

new topic     » goto parent     » topic index » view thread      » older message » newer message

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.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu