Technical data
520
-
Using Tcl ModelSim EE/PLUS Reference Manual
This is an example of using the Tcl
while
loop to copy a list from variable a to
variable b, reversing the order of the elements along the way:
set b ""
set i [expr[llength $a]-1]
while {$i >= 0} {
lappend b [lindex $a $i]
incr i -1
}
This example uses the Tcl
for
command to copy a list from variable a to variable
b, reversing the order of the elements along the way:
set b ""
for {set i [expr [llength $a] -1]} {$i >= 0} {incr i -1} {
lappend b [lindex $a $i]
}
This example uses the Tcl
foreach
command to copy a list from variable a to
variable b, reversing the order of the elements along the way (the
foreach
command iterates over all of the elements of a list):
set b ""
foreach i $a {
set b [linsert $b 0 $i]
}
This example shows a list reversal as above, this time aborting on a particular
element using the Tcl
break
command:
set b ""
foreach i $a {
if {$i = "ZZZ"} break
set b [linsert $b 0 $i]
}
This example is a list reversal that skips a particular element by using the Tcl
continue
command:
set b ""
foreach i $a {
if {$i = "ZZZ"} continue
set b [linsert $b 0 $i]
}
The last example is of the Tcl
switch
command:
switch $x {
a {incr t1}
b {incr t2}
c {incr t3}
}