Switch versus if/then/else ( was: Main menu puzzle, Klaus)

Graham Samuel livfoss at blueyonder.co.uk
Sun Feb 19 14:41:52 EST 2006


On  Sun, 19 Feb 2006 10:37:36 -0800 (PST), Judy Perry  
<jperryl at ecs.fullerton.edu> wrote:
> Mark,
>
> Right, again, my argument was less "IF-THENs rule and CASE-SWITCHes  
> suck"
> than IF-THENs are easier to read/learn/are more transparent for
> non/novice-programmers.

Just to add a tiny footnote to this: Judy, how would you tackle a  
situation where a user (or a handler) can put in say a number from 1  
to 50, and each of those numbers requires the program to carry out a  
different action? It wouldn't really be feasible to have a depth of  
50 if-then-elses, so if you want to stick to a simple sequential  
model, either you'd have to use a switch (case) statement, or  
alternatively a structure like a handler 'myHandler' containing 50  
statements like:

if my parameter = 33 then
  doMyThirtyThirdThing
  exit myHandler
end if

which - to me - looks pretty much the same in terms of transparency.

I guess this horse is pretty well dead by now.

Graham


------------------------------------------------------------------------ 
---
Graham Samuel / The Living Fossil Co. / UK and France




More information about the use-livecode mailing list