TCL脚本:
set a 10
while {$a < 1} {
puts $a
incr a
}预期输出:
10
9
8
7
6
5
4
3
2
1我正在尝试打印从10到1的数字。但它不起作用(它什么都不打印)。
有没有办法“减少”变量值(decr a)?
谢谢,
库马尔
发布于 2014-11-18 15:30:27
将条件更改为$a > 1,并使用incr a -1递减该值。这里我们给出的步长为-1。
发布于 2014-11-28 22:29:42
for循环也可以做到这一点
for {set i 10} {$i > 1} {incr i -1} {
puts $i
}发布于 2014-12-04 23:49:08
我认为你的循环体永远不会被执行,因为条件在第一次就会产生false。你可能想写">“而不是"<”。
https://stackoverflow.com/questions/26988796
复制相似问题