Re: switch statement

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

I like the switch statement, it's already saved me a tangle of if-statements.

I'd like to make a suggestion:

value = {1,2,3} 
switch value do 
 
case 1: -- code, break 
case (1+1): -- code runs if value = 2, break 
case (var - 12): -- code , break 
case (value < 4): -- if all the elements of value are < 4, break 
case (match("cow,value)): 
end switch 

Basically, if () are encountered, then call eval() to run the expression in the (). Besides, value is somewhat executeable in a sense, i do this in http.e, and it runs fine:

switch sendheader[idx][1] do  

And i believe it executes (to dig into sendheader) because nothing is known about sendheader at compile time except it's declared as a sequence.

How to make a select switch:

switch value do 
      case a: 
break case b: 
break case c: 
end switch 

Think of it as a new two-word keyword. I did not try it. Depending on the switch parser, it may loose it's footing and crash. Basic Eu doesn't care if "break" is on another or the same line, but i don't know where it sees "case" in the context of the stack of testable conditions. I just think of "break" as Pascal's ; eol tag:

case "GET": tempheader &= sendheader[idx][1] & sendheader[idx][2] & sendheader[idx][3] & " " & httpversion & "\r\n" break -- append the http version 

useless

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

Search



Quick Links

User menu

Not signed in.

Misc Menu