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

Mark Wieder mwieder at ahsoftware.net
Sun Feb 19 11:52:55 EST 2006


Judy-

Saturday, February 18, 2006, 9:27:39 PM, you wrote:

> Yes, but do you think in these terms in day-to-day life?

Your example isn't a reasonable candidate for a switch/case construct
because the conditionals aren't at the same level. Instead your ifs
are nested within each other, and that's an example of where and
if/then/else construct is much more readable. There's no reason to
convert that.

Where the switch statement comes into its own is where you have
multiple choices at the same level:

IF the paycheck arrives tomorrow THEN
  switch tomorrow
    case Saturday
    case Sunday
      Write the rent check two days later
      break
    default
      Write the rent check the day after
  end switch
END IF

> And, even if you do, it's still not how normal humans describe
> cause-and-effect phenomena in non-programming situations.

Actually, it is. When you come across "if tomorrow is a weekend day
THEN" you don't process it literally - your brain converts "weekend
day" into "let's see - is this a Saturday or a Sunday or something
else" and then returns to inline processing. So your brain is really
doing the switch/case process for you, expanding the shorthand
"weekend" into what that corresponds to, eventually returning a
boolean value to you and giving you the goahead to write the check.

Hope your check clears <g>

-- 
-Mark Wieder
 mwieder at ahsoftware.net




More information about the use-livecode mailing list