---- Original Message ----
From: David Marcus
To:
[email protected]
Sent: Wednesday, 2011. October 26. 15:39
Subject: RE: [Suggestions-t-3314] Re: Enhanced CASE values in SWITCH
| Quote:
|| Originally Posted by JohnQSmith
|| Multiple choices...
|| Pick one of the following: A B C D E
|
|| Repeated binary choices...
|| Is it A? Is it B? Is it C? Is it D? Is it E?
|
| Except the code doesn't really look like either of those. So, I'll
| stick with my statement that the difference is the need to repeat the
| "it", even though Steve says that "is only a small part".
Repeat code sample:
switch string
case F1[012]*
:: choice 1: 3-character name of function key
case F[1-9]*
:: choice 2: 2-character name of function key
case [0-9]*
:: choice 3: digit key
case [A-Z]*
:: choice 4: letter key
default
:: error - unacceptable character
endswitch
Why is this not of the mulitple choice type? BTW, I did implement it using IFF/ELSEIFF blocks thus:
iff %@wild[%x,F1[012]*] EQ 1 then
...
elseiff %@wild[%x,F[1-9]* EQ 1 then
...
etc. In code that is interpreted, there is probably no significant difference in performance. If it were compiled, the compiler could possibly optimize the SWITCH to the minimum number of comparisons better than the IFF could be optimized, but probably still not a significant difference in execution time.
What is the significant difference to me is that with SWITCH there is ONE place where the program branches, into one of 5 branches. With IFF / ELSEIFF there are FOUR branch points, with the same 5 branches. As I said before, IFF / ELSE is a special case of the multiple choice: binary choice. I personally prefer the single mulptle-choice to multiple binary choices.
--
Steve