Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Tcl loops and conditionals

Posted by admin (Graham Ellis), 4 September 2002
There seem to be an incredible number of people out there searching for "Tcl" and "loops" or "conditionals" on the search engines, or perhaps it's just that all such people get sent to our web site!

When you're writing Tcl, you must remember that it's a command based language, and that even the conditionalsand loops are commands.  You must also remember that
     square brackets are always performed EARLY
     curly braces are usually perfored LATE

Taking an example, the if command in its simplest form takes two parameters; the first is something that has to return a true or false value, and the second is the thing to do if the first is true.  Thus:
     if  $abc  exit
will cause the exit command to be run if the varaible $abc contains a true value, but the code will drop through to the following line if $abc contains a false value.

I repeat - it's the if COMMAND.  Thus the space after the command word, and th space between the first and second parameters is vital.   And if you want to put a new line between the parameters, you need to protect it with a \ character.

Using blocks in curly braces does allow you to specify a whole lot of follow up commands without having to protect every new line, and using curly braces for the condition does make the syntax a bit easier there too as the block is deferred and passed into the if command itself, which wraps it up in an expr for you.   Thus:
     if {$abc > 10} {
           puts "\$abc is big ..."
           puts "in fact, it contains $abc"
           }
works fine.

Posted by raju (raju), 16 September 2004
Dear Sir,
I have two variables which are needed to to change diffuse color and ambient color and I need to use for loop, But I am having problem declaring and incrementing the variables.I am getting error in the for loop.So, Please help me with a small example.
Thank You,
Raju

Posted by admin (Graham Ellis), 17 September 2004
Hi, welcome Raju.  

You're very welcome to ask about your code - please post up a few lines to show us the problems that you're having and I'll then know how best to advise you.

Graham

P.S.  Please start a NEW TOPIC - that way, our question and answer sequence won't get mixed up with the more general advise in this thread.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho