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 

Comments

Anonymous at 01 May, 2008 12:20
Really the presentation is superb nice site
At the same time mention how to run the code in unix/linux, Windows with examples
Reply to this.
princess at 14 Mar, 2009 02:52
can u help me,im really confused about this.im not a comp engineer or comsci but only in technical course and i have problem with this.how bout if the problem says like this?.: create a program using while and do while loop that enters a numbers in ascending order and will stop based on how much is the number being input by the user.
Reply to this.
Comment

Please dont enter you comments in this form - this is a fake form to confuse spamming bots. The next form is the real one.




Comment




Comment Formating : HTML tags a, strong, em, b, i, code, pre, p and br allowed. Other tags will be shown as code(< will become &lt;). Urls, Line breaks will be auto-formated.
Subscribe to Feed