Table of Contents

Getting started with Tcl: example 10

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

Arrays versus strings

Script

#!/usr/bin/tclsh
# arrays vs. strings
 
set Fibo(0) 1
set Fibo(1) 2
for { set i 2 } { $i < 10} { incr i} {
    set Fibo($i) [expr $Fibo([expr $i - 1]) + $Fibo([expr $i -2])]
    puts stdout "Fibo($i) = $Fibo($i)"
}
 
puts stdout "liste Fibo = [array get Fibo]"
 
puts stdout "" 
array set Tab {a alpha b beta c delta}
puts stdout "Tab(b) = $Tab(b)"

Output

Fibo(2) = 3
Fibo(3) = 5
Fibo(4) = 8
Fibo(5) = 13
Fibo(6) = 21
Fibo(7) = 34
Fibo(8) = 55
Fibo(9) = 89
liste Fibo = 8 55 4 8 0 1 9 89 5 13 1 2 6 21 2 3 7 34 3 5
 
Tab(b) = beta

<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