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

Judy Perry jperryl at ecs.fullerton.edu
Sun Feb 19 20:34:10 EST 2006


Graham,

Well, in the original context of this thread, I wouldn't.  I suspect that
there aren't many Inventive Users who would need that level of
functionality/programming expertise.  Certainly, the original poster for
this thread didn't (remember: it was a very short list of menu options).

And, again, in the spirit of the original postings of the thread, I'd say
this:

If-Thens are readily comprehensible by non/novice-programmers.

Case-Switch statements are preferred by "real" programmers.

Real Programmers can take a look at any given set of if-thens and
internally posit the corresponding, perhaps superior, case-switch
statement(s).

But it doesn't work the other way around.

Regards,

Judy


On Sun, 19 Feb 2006, 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
>
> which - to me - looks pretty much the same in terms of transparency.
>




More information about the use-livecode mailing list