Reputation: 717
TCL Script:
set a 10
while {$a < 1} {
puts $a
incr a
}
Expected output:
10
9
8
7
6
5
4
3
2
1
I am trying to print numbers from 10 to 1. But its not working (It prints nothing).
Is there a way to "decrement" the variable value (decr a)?
Thanks,
Kumar
Upvotes: 1
Views: 19807
Reputation: 1344
I think your loop body is never executed because the condition yields false the very first time. You probably wanted to write ">" instead of "<".
Upvotes: 0
Reputation: 243
same can be done by for loop also
for {set i 10} {$i > 1} {incr i -1} {
puts $i
}
Upvotes: 1
Reputation: 16428
Change the condition to $a > 1
and to decrement the value, you have to use incr a -1
. Here we gave the step as -1.
Upvotes: 4