学习每种语言都得学习这几个循坏
虽然各种语言都大差不差啦
但还是简单记录一下
一、for循环
1、指定元素循环
从打印的结果可以看出元素是以空格分割的
#!/usr/bin/expect
foreach i {2,3,5,9} {
puts $i
}
foreach i {q f v j} {
puts $i
}
2、自增循环
incr i 就是 i++
#!/usr/bin/expect
for {set i 0} {$i < 3 } {incr i} {
puts "now the num is: $i"
}
自增的另一种写法
#!/usr/bin/expect
set k 2
puts "now k is: $k"
set k [expr {$k +1}]
puts "after expr, k is: $k"
二、while
#!/usr/bin/expect
set j 0
while {$j < 3} {
puts "now j is: $j"
incr j
}
利用break跳出while
#!/usr/bin/expect
set j 0
while {1} {
puts "now j is: $j"
incr j
if {$j == 4} {
break
}
}
三、if-else
第一个参数为空打印null,不为空则打印参数内容
#!/usr/bin/expect
set content [lindex $argv 0]
if {$content == ""} {
puts "the content is null"
} else {
puts "the content is $content"
}
Over!如有错误烦请指出!谢谢!
参考自:https://www.cnblogs.com/iloveyoucc/archive/2012/06/17/2552553.html