Previous While Loop |
Tcl/Tk Tutorial Switch Loop |
Next Functions |
Evaluate one of several scripts, depending on a given value.
Syntax:switch ?options? string { pattern body ?pattern body ...? }
switch ?options? { string } {
pattern { body }
?pattern { body }
...?
}
-exact | Use exact matching when comparing string to a pattern. This is the default. |
-glob | When matching string to the patterns, use glob-style matching (i.e. the same as implemented by the string match command). |
-regexp | When matching string to the patterns, use regular expression matching |
#The marriage status script... #Change the status please set marital_status "After" label .thesis -text "Marriage is a three ring circus..." switch $marital_status { "Before" { set ring "Engagement" } "During" { set ring "Wedding" } default { set ring "suffe -" } } label .proof -text "$marital_status Marriage: $ring ring" pack .thesis pack .proof
Run this script and give the 'marital_status' to "Before", "During" and "After" and see the different results.
Previous While Loop |
Contents | Next Functions |