Difference between revisions of "Command:Case"
Jump to navigation
Jump to search
(2 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
== Description == | == Description == | ||
− | Used within a [[Command:Switch|Switch]], this marks the beginning of what should be executed if the text matches what was given to [[Command:Switch|Switch]]. | + | Used within a [[Command:Switch|Switch]], this marks the beginning of what should be executed if the text matches what was given to [[Command:Switch|Switch]]. You should '''not''' use quotes in a multiple-word case. The quotes for this command would be considered a part of the actual comparison, and would not match unless the switch expression had the same quotes! |
== Examples == | == Examples == | ||
Line 20: | Line 20: | ||
Default | Default | ||
echo "Please pick Red, Yellow, or Burnt Sienna" | echo "Please pick Red, Yellow, or Burnt Sienna" | ||
+ | break | ||
+ | } | ||
+ | EndSwitch | ||
+ | |||
+ | This example shows the use of fall through (i.e not putting a break statement after each case statement) | ||
+ | |||
+ | Switch "${DayOfTheWeek}" | ||
+ | { | ||
+ | case Monday | ||
+ | case Tuesday | ||
+ | case Wednesday | ||
+ | case Thursday | ||
+ | case Friday | ||
+ | echo "Its a weekday" | ||
+ | break | ||
+ | case Saturday | ||
+ | case Sunday | ||
+ | echo "Its the weekend" | ||
+ | break | ||
+ | Default | ||
+ | echo "${DayOfTheWeek} isnt a day I know how to deal with" | ||
break | break | ||
} | } | ||
Line 28: | Line 49: | ||
*[[LavishScript:Commands|Commands]] | *[[LavishScript:Commands|Commands]] | ||
{{Command-Stub}} | {{Command-Stub}} | ||
+ | [[Category:LavishScript]] | ||
+ | [[Category:LavishScript Commands]] |
Latest revision as of 21:55, 16 July 2005
Contents
Syntax
Case | |
Usage | Intermediate |
Level of Understanding | Intermediate |
Computer Savvy | Beginner |
Logic | Intermediate |
Case <text>
Description
Used within a Switch, this marks the beginning of what should be executed if the text matches what was given to Switch. You should not use quotes in a multiple-word case. The quotes for this command would be considered a part of the actual comparison, and would not match unless the switch expression had the same quotes!
Examples
Switch "${Crayon.Color}" { case Red echo "You picked the Red crayon" break case Yellow echo "You picked the Yellow crayon" break case Burnt Sienna echo "You picked the Burnt Sienna crayon" break Default echo "Please pick Red, Yellow, or Burnt Sienna" break } EndSwitch
This example shows the use of fall through (i.e not putting a break statement after each case statement)
Switch "${DayOfTheWeek}" { case Monday case Tuesday case Wednesday case Thursday case Friday echo "Its a weekday" break case Saturday case Sunday echo "Its the weekend" break Default echo "${DayOfTheWeek} isnt a day I know how to deal with" break } EndSwitch