set {a} 10 set b 12 set c 14 set d "14" set e [expr$d + 10 + 9] set res1 [expr$e / 9]; # the result is interger,Notice the semicolon here set res2 [expr$e/ 9.0]; # the result is float,Notice the semicolon here
10 { puts"the value is 10" } 20 { puts"the value is 20" } default { puts"no matching value" }
}
set b [expr$a == 10 ? 10 : 20] puts"the value of b is : $b \n"
#=====================
#Loop Stament
#=====================
while { $a < 40 } { incr a puts" the value of $a " }
for { set index $b} { $index < 30 } { incr index } {
puts" the value of index : $index "
if { $index == 21 } { incr index continue }
if { $index == 25 } { break }
}
#====================
#Proc
#====================
proc func1 {} {
puts"hello world"
}
proc func2 { a b } { return [ expr$a + $b ]
}
proc func3 { numbers } {
set sum 0 foreach number $numbers { set sum [ expr$sum + $number ] } set avg [ expr$sum / [ llength$numbers ]] return$avg }
proc func4 { a { b 10 } } {
return [ expr$a + $b ] }
proc func5 { num } { if { $num == 1 } { return1 }
return [ expr$num * [ func5 [ expr$num-1 ]]]
}
func1
puts [ func2 1020 ]
puts [func3 {102030}]
puts [func4 10 ]
puts [ func4 1020 ]
puts [ func5 5 ]
#================
#NameSpace
#===================
## define namespace namespaceeval MyMath {
variable myResult
namespaceeval MyMath_Inner {
variable myResult1
}
}
## set the variable And proc of the namespace proc MyMath::Add { a b } { set ::MyMath::myResult [ expr$a + $b ] set ::MyMath::myResult1 [ expr$a - $b ]
}
## print the varible And proc output of the namespace MyMath::Add 1023 puts$::MyMath::myResult puts$::MyMath::myResult1