Sponsored Content
Top Forums Shell Programming and Scripting Csh Programming Considered Harmful Post 302510218 by HARJINDER SINGH on Saturday 2nd of April 2011 03:00:53 AM
Old 04-02-2011
how to use foreach loop
 

10 More Discussions You Might Find Interesting

1. Programming

c programming or unix programming!?

i would like advice on the usbject of c programming (in the middle of reading a book on C). could i benefit more if i apply that knowledge in the unix format if i were able to, or would that take the point out of learning C, basically I want to stay away from strying too far away from unix and use... (1 Reply)
Discussion started by: moxxx68
1 Replies

2. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

3. UNIX for Dummies Questions & Answers

Carreer:Networking Programming in Unix (C programming Language)

Hello, I am trying to learn Networking Programming in C in unix enviorment. I want to know how good it is to become a network programmer. i am crazy about Network programming but i also want to opt for the best carreer options. Anybody experienced Network Programmer, please tell me is my... (5 Replies)
Discussion started by: vibhory2j
5 Replies

4. Programming

C: why decimals considered double by default ?

Can anybody tell me why any literal constant real numbers are double by default in C ? Why is the default not float ? (2 Replies)
Discussion started by: limmer
2 Replies

5. AIX

Background & is considered as Idle

Our Aix Unix has one issue. If I type xedit & after 30 minutes, xedit auto shut down. If I type xedit xedit will run forward. I feel this & doesn't perform as it should be. When I use &, system consider this process as idle. How to fix this issue? Does this mean unix env... (12 Replies)
Discussion started by: david_hu_66
12 Replies

6. Programming

Why is C/C++ considered low-level languages???

Hi friends, I hope everyone is doing well and fine. I have always been hearing that C/C++ are relatively low-level as compared to Java/C# etc. Could you please tell me some low-level qualities of C/C++? And I think disk deframenters are written in C/C++, please correct me if I am wrong. And please... (5 Replies)
Discussion started by: gabam
5 Replies

7. Forum Support Area for Unregistered Users & Account Problems

Google reporting UNIX.com as harmful site

Google is reporting unix.com as harmful site. For example, if one types site:unix.com php into the Google search box, Google says Migration of website... PHP/Mysql -which path for DB.php - The ... This site may harm your computer. 7 posts - 3 authors - May 28 Hi, I have two websites:... (6 Replies)
Discussion started by: Unregistered
6 Replies

8. Shell Programming and Scripting

Considered basic but advanced outcome (Custom Backup Solution)

Ive a problem that I'm reaching out for help. Ive written (With bits and pieces) of script that is not running as expected or is having an issue causing processes to spiral out of control. The script does this: Unloads a UV database server Tars up a few folders Transfers the file to... (11 Replies)
Discussion started by: coastdweller
11 Replies

9. UNIX for Dummies Questions & Answers

From iOS programming to Linux system programming

Hello. I like Linux and C programming language. Allways wanted to understand kernel and become a Linux system programmer. And I also like Objective-C and iOS. These two programming areas have relations: 1. Linux and iOS are UNIX-like systems, POSIX compliant. 2. It is useful to know C language... (2 Replies)
Discussion started by: Rockatansky
2 Replies

10. Homework & Coursework Questions

Time command issuing all zeroes (is now considered homework help)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: A common problem arising in games and simulations is to generate a random arrangements of integers from 1 to N.... (5 Replies)
Discussion started by: lamentofking
5 Replies
foreach(n)						       Tcl Built-In Commands							foreach(n)

__________________________________________________________________________________________________________________________________________________

NAME
foreach - Iterate over all elements in one or more lists SYNOPSIS
foreach varname list body foreach varlist1 list1 ?varlist2 list2 ...? body _________________________________________________________________ DESCRIPTION
The foreach command implements a loop where the loop variable(s) take on values from one or more lists. In the simplest case there is one loop variable, varname, and one list, list, that is a list of values to assign to varname. The body argument is a Tcl script. For each element of list (in order from first to last), foreach assigns the contents of the element to varname as if the lindex command had been used to extract the element, then calls the Tcl interpreter to execute body. In the general case there can be more than one value list (e.g., list1 and list2), and each value list can be associated with a list of loop variables (e.g., varlist1 and varlist2). During each iteration of the loop the variables of each varlist are assigned consecutive values from the corresponding list. Values in each list are used in order from first to last, and each value is used exactly once. The total number of loop iterations is large enough to use up all the values from all the value lists. If a value list does not contain enough elements for each of its loop variables in each iteration, empty values are used for the missing elements. The break and continue statements may be invoked inside body, with the same effect as in the for command. Foreach returns an empty string. EXAMPLES
This loop prints every value in a list together with the square and cube of the value: set values {1 3 5 7 2 4 6 8} ;# Odd numbers first, for fun! puts "Value Square Cube" ;# Neat-looking header foreach x $values { ;# Now loop and print... puts " $x [expr {$x**2}] [expr {$x**3}]" } The following loop uses i and j as loop variables to iterate over pairs of elements of a single list. set x {} foreach {i j} {a b c d e f} { lappend x $j $i } # The value of x is "b a d c f e" # There are 3 iterations of the loop. The next loop uses i and j to iterate over two lists in parallel. set x {} foreach i {a b c} j {d e f g} { lappend x $i $j } # The value of x is "a d b e c f {} g" # There are 4 iterations of the loop. The two forms are combined in the following example. set x {} foreach i {a b c} {j k} {d e f g} { lappend x $i $j $k } # The value of x is "a d e b f g c {} {}" # There are 3 iterations of the loop. SEE ALSO
for(n), while(n), break(n), continue(n) KEYWORDS
foreach, iteration, list, looping Tcl foreach(n)
All times are GMT -4. The time now is 01:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy