Previous
For Loop 
Next
Switch Loop 
Tcl/Tk Tutorial - Create GUI using Tk with Tcl Language
While Loop

The Control Flow Loops

While Loop

Execute script repeatedly as long as a condition is met. In the given syntax, test is the condition and body is the script. As long as test is true, the script will be executed repeatedly.

Syntax:
while test body

I like this syntax better...
while { test } {
body
}

The same program we used for the "for" loop. Now presenting - The While loop -


#Multiplication table...
set n 4 ;# We want the multiplication table of 4
set table ""
set i 1
while { $i <= 10 } {
# This will append all multiples of all numbers for the number n 
#		into a variable called table
	set table "$table $i x $n = [expr $i \* $n]\n"
	incr i
}

label .mul -text "Multiplication table for $n\n\n$table"
pack .mul
Previous
For Loop 
Next
Switch Loop 
Subscribe to Feed