Re: case and foreach
- Posted by ZNorQ <znorq at holhaug.com> Apr 01, 2005
- 536 views
D. Newhall wrote: > > I too have yearned for the "case", "foreach", and "next" statements. However, > one of > Euphoria's goals is to keep the code simple and these suggestions kinda run > against > that trend. Regardless, I've found myself wishing I had a "next" statementmany > times > when I need to find all possible permutations of a certain string. Also, if > you look > at probably 90% of for loops, they seem to be used in instances where > "foreach" would > be much better. > > "Case" I'm torn on. While yes "select" and "case" would be excellent things to > add > you don't really need them. Yes, they'd increase productivity and probably > make it > easier to debug but they aren't necessary, "if" and "then" work perfectly fine > (even > if it takes longer to type all the conditions in). > > "Next" we can live without but most people seem to want "foreach" and > "select/case". > > Here's my suggestion for the syntax: > > -- select/case > select x do > case 5 then > -- code > end case > case 2 then > --code > end case > end select > > -- foreach > foreach o in s by 1 do -- o is an object > -- code > end foreach > My proposal for SELECT; select x do case 0 -- code case 1 to 4 -- code case 5 or 7 --code case 6 or 8 to 9 --code case else -- code end select I would hope the keywords 'End Case' and 'Then' wouldn't be necessary. (I think it's cleaner, don't know about you guys?) Hope the 'or' and 'to' is self-explanatory. Maybe using ',' comma instead of 'or' might be better, I really don't know. I've also added 'Case Else' so that 'select' can cope with any values that aren't considered in the case list. Derek, you argue that 'select' (among others) runs against the Euphoria goal to keep it simple, and I disagree that 'select' does exactly that. I think select is a clean and simple way to determine the content of a single variable. Last time I proposed some additions to Euphoria, I got a rather crude reply - so I'll say this; I love Euphora as it is, I'm just proposing some of my views of what would make Euphoria more powerful AND simple! :D Kenneth/ZNorQ