10.0;for, revision 1.0, 88/01/21 for -- Execute a for statement. usage: for var_name := int_expr [to int_expr] [by int_expr] command... endfor for var_name in string_expr [by {char|word|line}] command... endfor NAME for - execute a for statement SYNOPSIS for var_name := int_expr [to int_expr] [by int_expr] command... endfor for var_name in string_expr [by {char|word|line}] command... endfor DESCRIPTION for allows you to build a control structure that executes commands repeatedly as long as the result of a Boolean test is true. The for command has two formats: one for assigning and testing integer expressions; the other for assigning and testing string expressions. In the integer form, the (optional) to and by clauses permit you to specify ranges and increment values, respectively. For example, you might want to loop five times by specifying for a := 0 to 10 by 2 If you do not specify by int_expr, the default increment is 1. If you do not specify to int_expr, you probably want to increment the variable manually inside the body of the loop. You should also put a test condition inside the loop (and probably use an exit to get out) or you risk looping forever. In the string form, the (optional) by clause allows you to control the string assignment operation. If you specify by word (the default), each word (a sequence of non-blank characters) in string_expr is assigned to var_name one at a time until string_expr is exhausted. You may also assign string values a character at a time, or a line at a time, by using the by char and by line clauses, respectively. ARGUMENTS var_name (required) Specify the name of the shell variable whose value is to be assigned and tested. int_expr (required) Specify any valid expression that returns an integer value. string_expr (required) Specify any valid expression that returns a string value. command... (required) Specify the command to be executed as long as the for test returns true. This may be a shell command, a shell script, a variable assignment, or any other valid shell operation. Multiple commands are permitted; separate them with semicolons or newline characters. EXAMPLES The following example demonstrates the advantages of a for loop over a while loop in one instance. Assume these lines appear in a shell script. # A loop using while. eon a := 0 while ((^a <= 10)) do args ^a a := ^a + 2 enddo # # The same loop using for. # for a := 0 to 10 by 2 args ^a endfor # # End of script. This example assigns three names to a variable. # # Script file_name # eon for file in "foo bar zap" by word args ^file endfor # # end of script. Execution produces this: $ file_name foo bar zap $