Difference between revisions of "Command:Switch"

From Lavish Software Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
== Syntax ==
 
== Syntax ==
 
{{CMD-DR|Switch|Intermediate|Intermediate|Beginner|Intermediate}}
 
{{CMD-DR|Switch|Intermediate|Intermediate|Beginner|Intermediate}}
 +
Switch <text>
  
 
== Description ==
 
== Description ==
 +
Executes one of many conditional branches, depending on the value of the switch.  Cases are checked for equality (case insensitive).  The first case to match exactly will be executed.  If no explicitly defined cases match, the Default, if any, will be executed.  [[Command:EndSwitch|EndSwitch]] must be used to end the switch.
  
 
== Examples ==
 
== Examples ==
 +
Switch ${Fruit.Color}
 +
{
 +
  case Red
 +
    echo Is the fruit a strawberry?
 +
    break
 +
  case Blue
 +
    echo Is the fruit a blueberry?
 +
    break
 +
  case Yellow
 +
    echo Is the fruit a banana?
 +
    break
 +
  Default
 +
    echo I don't know what kind of fruit might be ${Fruit.Color}!
 +
    break
 +
}
 +
EndSwitch
  
 
== See Also ==
 
== See Also ==
 +
*[[LavishScript:Control Structures]]
 +
*[[Command:Break|Break]]
 +
*[[Command:Case|Case]]
 +
*[[Command:Default|Default]]
 +
*[[Command:EndSwitch|EndSwitch]]
 
*[[LavishScript:Commands|Commands]]
 
*[[LavishScript:Commands|Commands]]
 
{{Command-Stub}}
 
{{Command-Stub}}

Revision as of 01:31, 24 March 2005

Syntax

Command Difficulty Rating
Switch
Usage Intermediate
Level of Understanding Intermediate
Computer Savvy Beginner
Logic Intermediate

Switch <text>

Description

Executes one of many conditional branches, depending on the value of the switch. Cases are checked for equality (case insensitive). The first case to match exactly will be executed. If no explicitly defined cases match, the Default, if any, will be executed. EndSwitch must be used to end the switch.

Examples

Switch ${Fruit.Color}
{
  case Red
    echo Is the fruit a strawberry?
    break
  case Blue
    echo Is the fruit a blueberry?
    break
  case Yellow
    echo Is the fruit a banana?
    break
  Default
    echo I don't know what kind of fruit might be ${Fruit.Color}!
    break
}
EndSwitch

See Also