Getting started with Tcl: example 5

This page is part of the Airplug documentation related to Tcl/Tk.
Back to the Tcl/Tk documentation page / Back to the Airplug documentation page

Using arrays, for, foreach

Script

#!/usr/bin/tclsh
# Using arrays, for, foreach
 
set tableau(1) un
set tableau(2) deux
set tableau(3) trois
 
for {set i 1} { $i <= 3 } {incr i} {
  puts stdout "tableau($i) = $tableau($i)"
}
 
puts stdout ""
set tableau(tcl) {c'est super}
set tableau(fleur) {la rose}
 
foreach index [array names tableau] {
  puts stdout "tableau($index) = $tableau($index)"
}

Output

tableau(1) = un
tableau(2) = deux
tableau(3) = trois
 
tableau(1) = un
tableau(fleur) = la rose
tableau(2) = deux
tableau(tcl) = c'est super
tableau(3) = trois

<br/>


This page is part of the Airplug documentation related to Tcl/Tk.
Back to the Tcl/Tk documentation page / Back to the Airplug documentation page

 
Back to top
en/doc/pub/tcltk/example-05.txt · Last modified: 2017/04/05 16:06 (external edit)
 
 
Driven by DokuWiki