Re: New switch/case idea

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

Does that mean the meaning of break depends on context ?

Yes, just like exit or continue or retry (the last two are new in 4.0). This is to prevent having to invent extra flags and create extremely convoluted control flow:

integer exit_i = 0 
for i = 1 to 10 do 
    for j = 1 to 10 do 
        if foo(j) > bar(i) then 
            exit_i = 1 
            exit 
        end if 
    end for 
    if exit_i then 
        exit 
    end if 
end for 

That code could (in 4.0) be simplified:

for i = 1 to 10 label "i" do 
    for j = 1 to 10 do 
        if foo(j) > bar(i) then 
            exit "i" 
        end if 
    end for 
end for 

Matt

Thanks Matt, but what I was trying to ask concerning context was:

  • break inside a switch aborts the switch;
  • But if the switch is inside an if-then statement, break aborts the if-then ?, i.e., break works different if the switch is inside an if-then or not ? IIUC, Jeremy replied that break doesn't depend on the context.

Maybe this example helps me:

X = 1 
condition = 1 
switch X do 
   case 1 then 
      if condition then break end if 
      X = 2 
end switch 
? X 

If that is valid, what will be showed ?

- Fernando

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

Search



Quick Links

User menu

Not signed in.

Misc Menu