码迷,mamicode.com
首页 > 其他好文 > 详细

tcl脚本学习六:switch的学习

时间:2016-08-03 00:03:53      阅读:1335      评论:0      收藏:0      [点我收藏+]

标签:

lesson 6 :switch 的用法


;# Set the variables we‘ll be comparing
set x "ONE";
set y 1;
set z "ONE";
//例子的基本数值


1. switch $x \
"ONE" "puts ONE=1" \
"TWO" "puts TWO=2" \
"default" "puts NO_MATCH";
//switch 的基本用法

 


2. switch $x \
"$z" {set y1 [expr $y+1]; puts "MATCH \$z. $y + $z is $y1" } \
"ONE" {set y1 [expr $y+1]; puts "MATCH ONE. $y + one is $y1"} \
"TWO" {set y1 [expr $y+2]; puts "MATCH TWO. $y + two is $y1" } \
"THREE" {set y1 [expr $y+3]; puts "MATCH THREE. $y + three is $y1" } \
"default" {puts "$x does not match any of these choices";}
//强调!! 这里的{}不再具有之前puts里面的原封不动输出括号内的意思,而是将该条件下的成立后的条件包括起来

;# This form of the command disables variable substitution in the pattern

3.switch $x {
"$z" {set y1 [expr $y+1]; puts "MATCH \$z. $y + $z is $y1" }
"ONE" {set y1 [expr $y+1]; puts "MATCH ONE. $y + one is $y1"}
"TWO" {set y1 [expr $y+2]; puts "MATCH TWO. $y + two is $y1"}
"THREE" {set y1 [expr $y+3]; puts "MATCH THREE. $y + three is $y1"}
"default" {puts "$x is NOT A MATCH"}
}

tcl脚本学习六:switch的学习

标签:

原文地址:http://www.cnblogs.com/gold-life/p/5731126.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!