tcl for loop This is a topic that many people are looking for. militaria-agent.com is a channel providing useful information about learning, life, digital marketing and online courses …. it will help you have an overview and solid multi-faceted knowledge . Today, militaria-agent.com would like to introduce to you Loop construct in TCL– While loop, For loop and Foreach Loop. Following along are instructions in the video below:
“Guys so in this lecture. We will see loop statement in tcl programming. So in in the first loop available in tcl is while. But the difference between while in and while in see in tcl.
This file is your command okay and so in the syntax is almost similar to the syntax. We are having in c programming. While after while we have to specify the condition. But the condition in tcl is specified in curly braces then the opening curly braces and here will be the closing.
So here. We will specify the condition so for condition. Let s declare a variable i and zero so we have just take rated a variable i and we assign value zero and let s say we want to run this loop. Ten times.
So the condition will be dollar. I less than ten. So this loop will run from zero to nine ten ten times. So it will be ten times.
Let s say we will print the value of i now in order to break this condition. We have to keep on increasing the value of i so we can use exp our command like right sorry like set. I so we have to assign increased value in i so we will write exp are to perform addition dollar. I plus one so this is statement this exp.
Our command will perform this operation so value will be let us say initially it will be one and this entire expression from here to here this will be replaced by its output. Because we have enclosed this one in big bracket. So the role of big bracket replace the entire expression with the output and this i will be assigned that increased value in case. If you are not comfortable with this one.
There is a short version or also available in tcl. The i and cr. I so this one is the similar one with the previous so this the incr command. It will increase val you of i buy one every time this is caught so now if we will run this program.
Tcl sh show dot tcl. So this program. So this lobe is earning ten times. So this is the first loop available in tcl programming.
Now let s see the second loop. Which is for loop. So for loop. The syntax of for loop is like for then first we have to initialize initialization part of our variable.
Which will be specified in curly braces. Then condition checking and then finally i increment or decrement. And then the opening body and here will be closing body. So.
The syntax is similar and here also we are having three part. But their syntax little bit different from the c. We are not having a brace. We are not having any semicolon.
All the part are separated by curly braces. So let s write a program. So we want to print 0 to 9 same program. So here we will write set i 0.
Second part a condition checking dollar. I less than 10 and third. Part is increment. So i ncr.
I and opening and here we will write a statement to print value of i so this this one is similar to the previous one so now if you can see this for loop. Actually reduce the number of statement needed to be written so if we run this program again this program also doing the same task. But we have to write less number of instructions so this for loop. Having initialization here.
This is condition checking here. And this is increment or decrement. So how it executes first it will set this value to i then it will check the condition. If the condition is true.
This is statement in executed. Then it will increase the value it will again check the condition. The condition is true it will enter in the body. So this initialization part this one will be executed.
Only one time in the beginning. Now. There is one more loop construct available in tcl. This actually used for lists.
So let s let s create a list in tcl. If you want to create a list. We have to use curly. Braces and then let s say we have created a list with three elements.
So list actually a collection of variety of data. We can store string number anything in list. So the syntax for this one is for each so it will iterate over the list then a temporary variable lets safety and then value up list and here this is opening and here what we want to do we want to print value of every element. So if we our program.
So this for each in case. If we are having a list and if we want to iterate if you want to process every element of that list we can go for for ” ..
Thank you for watching all the articles on the topic Loop construct in TCL– While loop, For loop and Foreach Loop. All shares of militaria-agent.com are very good. We hope you are satisfied with the article. For any questions, please leave a comment below. Hopefully you guys support our website even more.