Getting started with Tcl: example 6

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 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}

<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-06.txt · Last modified: 2017/04/05 16:08 (external edit)
 
 
Driven by DokuWiki