Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specification 15 Statements 15.8 Iteration statements 15.8.3 The for statement
Paragraph 11 The for statement evaluates a sequence of initialization expressions and then, while a condition is true, repeatedly executes an embedded statement and evaluates a sequence of iteration expressions. for-statement : for ( for-initializeropt ; for-conditionopt ; for-iteratoropt ) embedded-statement for-initializer : local-variable-declaration statement-expression-list for-condition : boolean-expression for-iterator : statement-expression-list statement-expression-list : statement-expression statement-expression-list , statement-expression
Paragraph 21 The for-initializer, if present, consists of either a local-variable-declaration (§15.5.1) or a list of statement-expressions (§15.6) separated by commas. 2 The scope of a local variable declared by a for-initializer starts at the local-variable-declarator for the variable and extends to the end of the embedded statement. 3 The scope includes the for-condition and the for-iterator.
Paragraph 31 The for-condition, if present, must be a boolean-expression (§14.16).
Paragraph 41 The for-iterator, if present, consists of a list of statement-expressions (§15.6) separated by commas.
Paragraph 51 A for statement is executed as follows:
Paragraph 61 Within the embedded statement of a for statement, a break statement (§15.9.1) may be used to transfer control to the end point of the for statement (thus ending iteration of the embedded statement), and a continue statement (§15.9.2) may be used to transfer control to the end point of the embedded statement (thus executing another iteration of the for statement).
Paragraph 71 The embedded statement of a for statement is reachable if one of the following is true:
- 2 If a for-initializer is present, the variable initializers or statement expressions are executed in the order they are written. 3 This step is only performed once.
- 4 If a for-condition is present, it is evaluated.
- 5 If the for-condition is not present or if the evaluation yields true, control is transferred to the embedded statement. 6 When and if control reaches the end point of the embedded statement (possibly from execution of a continue statement), the expressions of the for-iterator, if any, are evaluated in sequence, and then another iteration is performed, starting with evaluation of the for-condition in the step above.
- 7 If the for-condition is present and the evaluation yields false, control is transferred to the end point of the for statement.
Paragraph 81 The end point of a for statement is reachable if at least one of the following is true:
- 2 The for statement is reachable and no for-condition is present.
- 3 The for statement is reachable and a for-condition is present and does not have the constant value false.
- 2 The for statement contains a reachable break statement that exits the for statement.
- 3 The for statement is reachable and a for-condition is present and does not have the constant value true.
|Jagger Software Ltd|
|Company # 4070126|
|VAT # 762 5213 42|