Visible to Intel only — GUID: mwh1410471030225
Ixiasoft
Visible to Intel only — GUID: mwh1410471030225
Ixiasoft
2.9.7. Control Structures
If-Then-Else Structure
if { $a > 0 } { puts "The value is positive" } elseif { $a < 0 } { puts "The value is negative" } else { puts "The value is zero" }
The following example uses a for loop to print each element in a list.
For Loop
set a { 1 2 3 } for { set i 0 } { $i < [llength $a] } { incr i } { puts "The list element at index $i is [lindex $a $i]" }
The following example uses a foreach loop to print each element in a list.
foreach Loop
set a { 1 2 3 } foreach element $a { puts "The list element is $element" }
The following example uses a while loop to print each element in a list.
while Loop
set a { 1 2 3 } set i 0 while { $i < [llength $a] } { puts "The list element at index $i is [lindex $a $i]" incr i }
You do not have to use the expr command in boolean expressions in control structure commands because they invoke the expr command automatically.