Looping In TCL

 In Conditionals In TCL, we have learnt about the if command and the switch command. In this post we will learn about the while command, the for command and the incr command.

Here we are going to write a file named looping.tcl and then we will run it as, tclsh looping.tcl 

set cnt 10

puts "Descending order";

while {$cnt > 0} {

puts "cnt = $cnt";

set cnt [expr {$cnt - 1}];

}

puts "Even numbers";

while {$cnt < 11} {

if {$cnt % 2 == 0} {

puts "cnt = $cnt";

}

# set cnt [expr {$cnt + 1}];

set cnt [incr cnt];

}

puts "Odd numbers";

while {$cnt > 0} {

set cnt [incr cnt -1];

if {$cnt % 2 == 0} continue;

puts "cnt = $cnt";

if {$cnt < 3} break;

}

for {set idx 1} {$idx < 11} {incr idx} {

if {$idx % 2 == 0} continue;

puts "idx = $idx";

if {$idx > 8} break;

}

Happy reading and thank you. Meet you soon.

Comments

Popular posts from this blog

Bash Shell In Linux

Creating An Animation Using A Text Editor

expr command In TCL