| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
4.10 For statement
|
for domain : statement for domain : { statement … statement } |
- Where:
domain is an indexing expression which specifies the subscript domain of the for statement. (The colon following the indexing expression may be omitted.)
statement is a statement which should be executed under control of the for statement;
statement, …, statement is a sequence of statements (enclosed in curly braces) which should be executed under control of the for statement.
- Note:
Only the following statements are allowed within the for statement: check, display, printf, and another for.
Examples
for {(i,j) in E: i != j}
{ printf "flow from %s to %s is %g\n", i, j, x[i,j];
check x[i,j] >= 0;
}
for {i in 1..n}
{ for {j in 1..n} printf " %s", if x[i,j] then "Q" else ".";
printf("\n");
}
for {1..72} printf("*");
|
The for statement causes executing a statement or a sequence of statements specified as part of the for statement for every n-tuple in the domain set. Thus, statements within the for statement may refer to dummy indices introduced in the corresponding indexing expression.
