Andrew McDonough

Please note: This page is imported from my wiki, which hasn't been updated in over 10 years. Some of the formatting was lost during the import. I'll try to get around to fixing it someday.




Tcl supports scalar variables and associative arrays.

Variables can be assigned and read using the set command. set s {This is a string} => This is a string set n 17 => 17 set s => This is a string

Associative Arrays

set scores(Andrew) 95 set scores(Geoff) 87

The dollar ($) symbol is used to reference a previously set variable The expr keyword is used to mean evaluate and substitute.

set totalScores 0 for name (Andrew Geoff) { set totalScores [expr $totalScores + $scores($name) }

^ Java ^ Tcl ^ | i++ | incr i | | i += 2 | incr i 2 | | append s {Hello} | s += Hello |


Control Flow


if {$a > 5} { set a 0 }

if {$a == 0} { set a 1 } elseif {$a == 1} { set a 2 } else { set a 0 }

Note that the start brace must appear on the same line as the if statement.


foreach i $a { }

Initialiases i to each value of last a in turn.

Andrew McDonough

Andrew McDonough is a consultant CTO and software developer, currently based between Berlin and London.

Follow Andrew on Twitter or Connect on LinkedIn