Tcl : Creating Array

Tcl array can be created by set command by specifying its key to array name.

From example above we define array named days with keys containing numbers and text values. If we try to do variable substitution with $days, it wont work. If we do variable substitution with key specified then it will work.

We can have text as array’s key. Tcl array is an associative array.

From sample above we know that a text key is case sensitive (ID is different with id).

Another way to create array is with array set command by passing list of key value pairs as 3rd parameter and array name as 2nd parameter.

Thats all how we create array in Tcl. Bye!

Tcl : for command

For command used on tcl to create looping with syntax below :

for start test next command

for command have 4 parameter. The first parameter is start block where we set an initial value to a variable (usually using set command). Second parameter is test block where we test a variable or condition(will be tested using expr command). The third parameter is next block which usually used to change variable value (can use incr command). The fourth parameter is command which will be executed in loop.

Basic example below , using i as variable :

Continue reading Tcl : for command