Intel® Quartus® Prime Pro Edition User Guide: Scripting

ID 683432
Date 12/13/2021
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents
Give Feedback

2.9.7. Control Structures

Tcl supports common control structures, including if-then-else conditions and for, foreach, and while loops. The position of the curly braces as shown in the following examples ensures the control structure commands are executed efficiently and correctly. The following example prints whether the value of variable a positive, negative, or zero.

 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 elem