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

Geoff Canyon gcanyon at inspiredlogic.com
Sun Feb 19 17:27:07 EST 2006


On Feb 19, 2006, at 11:41 AM, Graham Samuel wrote:

> 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

Just to beat on the horse some more, given the above problem  
statement, I would likely store the names of the fifty handlers in a  
custom property, and do the following:

do (line myParameter of the uHandlerList of this cd)



More information about the use-livecode mailing list