Re: switch statement

new topic     » goto parent     » topic index » view thread      » older message » newer message
euphoric said...
jeremy said...
sequence value = "red" 
 
switch value do 
  case "apple": 
  case "pear": 
  case "orange": 
    puts(1, "It's a fruit!\n") 
    break 
 
  case "yellow": 
  case "blue": 
  case "red": 
    puts(1, "It's a color!\n") 
    break 
 
  case else 
    puts(1, "I have no clue what it is sad\n") 
end switch 
 
-- Output is "It's a color!" 

This is still the dumbest conditional construct I've ever encountered. Didn't the devs discover that in most cases, break will be used and, therefore, making it NOT default is the friendlier option?

And go against every other programming languages definition of a switch, I don't think that would be wise. Sure, we are not PHP, but people understand an if statement. What if we were to flip it around? People would be totally confused.

if 1=1 then 
  puts(1, "1 is not = 1\n") 
else 
  puts(1, "1 is 1\n") 
end if 

This is the same as changing the way switch works. It's totally foreign for the switch construct.

euphoric said...

I understand that your example above is not an optimal use case for switch, but I've never actually seen one either. Can you access the dev list archives? Maybe there was a convincing example there.

Um, actually my example of the colors, fruits, etc... is a valid construct for switch. There's nothing wrong with that example.

euphoric said...

And isn't there a select construct available in 4.0? I thought I had seen and even used it. getlost

No.

euphoric said...

Anyway, why not something like this:

sequence 
   value = "red" 
  ,fruits = {"apple","pear","orange"} 
 
switch value do 
  case in fruits: 
    puts(1, "It's a fruit!\n") 
 
  case in {"yellow","blue","red"}: 
    puts(1, "It's a color!\n") 
 
  case else 
    puts(1, "I have no clue what it is sad\n") 
end switch 
 
-- Output is "It's a color!" 

This takes away quite a bit of power from switch as you cannot do specific things based on one item. I was working up an example and then I saw that ghaberek just posted one...

said...

By the way, it doesn't look like select or switch are documented in the Manual! Or did I just miss it? sad

http://openeuphoria.org/docs/eu400_0010.html#_103_switchstatement

Jeremy

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

Search



Quick Links

User menu

Not signed in.

Misc Menu