Switch Statement

Rob Cozens rcozens at pon.net
Thu Jul 12 11:14:53 EDT 2007


Hi David,

>I use the switch statement a lot - but only for basic "case" tests and
>have not been able to get:
>
>    "If the caseValue is equal to the switchExpression, or the
>caseCondition evaluates to true"

Don't forget that switch logic falls through from case to case if 
there is no "break" statement; so

    [put whatEver into switchExpression]
    switch
         case caseValue = switchExpression
         case caseCondition = true
                 [case logic]
                 break
         default
                 [optional default logic]
     end switch

>working. Here is an example that I just changed from "if then else" -
>whats wrong with it:

You are combining two forms of the switch statement.  By designating 
mainChoice as the switch, the value of each case is compared to 
nainChoice.  Try:

    switch mainChoice
         case "Go to script object"
             break
         case empty
         case "This menu script"
             put the long id of me into scriptObject
             break
         case "Library 1"
         case "Library 2"
         ...
         case "Library n"
             put the name of stack secondChoice into scriptObject
             break
         case "Unsorted"
             edit the script of stack "libOPN_Unsorted"
             break
         default
             breakpoint
     end switch

This assumes a finite number of libraries with known names.

Rob Cozens CCW
Serendipity Software Company

"And I, which was two fooles, do so grow three;
  Who are a little wise, the best fooles bee."

  from "The Triple Foole" by John Donne (1572-1631) 




More information about the Use-livecode mailing list