====== Getting started with Tcl: example 6 ======
This page is part of the Airplug documentation related to Tcl/Tk.\\
[[en:doc:pub:tcltk:start|Back to the Tcl/Tk documentation page]] /
[[en:doc:summary|Back to the Airplug documentation page]]
===== Using lists, for, foreach =====
==== Script ====
#!/usr/bin/tclsh
# lists
set MyList { 1 2 }
puts stdout "MyList = $MyList"
set MyMetaList [list $MyList nice to meet you]
puts stdout "MyMetaList = $MyMetaList"
puts stdout ""
# for
for { set i 0 } { $i < 10 } { incr i 3 } {
# Listes [...]
lappend MyList $i
puts stdout "$i has been added to the list $MyList"
}
puts stdout ""
# foreach
foreach j $MyList {
puts stdout "there is $j in the list \{$MyList\}"
}
==== Output ====
MyList = 1 2
MyMetaList = { 1 2 } nice to meet you
0 has been added to the list 1 2 0
3 has been added to the list 1 2 0 3
6 has been added to the list 1 2 0 3 6
9 has been added to the list 1 2 0 3 6 9
there is 1 in the list {1 2 0 3 6 9}
there is 2 in the list {1 2 0 3 6 9}
there is 0 in the list {1 2 0 3 6 9}
there is 3 in the list {1 2 0 3 6 9}
there is 6 in the list {1 2 0 3 6 9}
there is 9 in the list {1 2 0 3 6 9}
----
This page is part of the Airplug documentation related to Tcl/Tk.\\
[[en:doc:pub:tcltk:start|Back to the Tcl/Tk documentation page]] /
[[en:doc:summary|Back to the Airplug documentation page]]