Re: New switch/case idea

new topic     » goto parent     » topic index » view thread      » older message » newer message
jeremy said...
mattlewis said...

It could be 'useful' if you jumped around using goto.

In that case you should use a goto to jump out of the if, IMHO. Here is presumably what you are speaking of?

integer X = 1 
if X > 0 then 
    X += 1    
 
    if X = 2 then 
        goto "continue_if" 
    end if 
 
    X = 0 
 
    break 
 
glabel "continue_if" 
    X += 3 
end if 

It enters the first if, making X 1, then the second making X 2, and it jumps and adds 3 more to X, making X 5. However, if X were, say 20, then X would have 1 added to it, then be 21, not meet the 2nd if's condition and become 0.

I'd probably write the above as (if I was that contorted):

integer X = 1 
if X > 0 then 
    X += 1    
 
    if X <> 2 then 
        X = 0 
        goto "done" 
    end if 
 
    X += 3 
end if 
 
glabel "done" 

Thing is it can still be accomplished w/o an empty break and if they are going to be using goto anyway, better for just one jump.

Jeremy

Really? I'd write it more like ...

if X > 0 then 
    X += 1    
 
    if X = 2 then 
        X = 5 
    else 
        X = 0 
    end if 
 
end if 

No labels nor goto.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu