Variable Arguments In TCL

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

 proc addall {args} {

set sum 0;

if {[llength $args] != 0} {

foreach num $args {

set sum [expr {$sum + $num}];

}

}

return $sum;

}

puts "Sum: [addall 2 3]";

puts "Sum: [addall 1]";


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