CodeIterationStatement Class
Represents a for statement, or a loop through a block of statements, using a test expression as a condition for continuing to loop.
Assembly: System (in System.dll)
System.CodeDom::CodeObject
System.CodeDom::CodeStatement
System.CodeDom::CodeIterationStatement
| Name | Description | |
|---|---|---|
![]() | CodeIterationStatement() | Initializes a new instance of the CodeIterationStatement class. |
![]() | CodeIterationStatement(CodeStatement^, CodeExpression^, CodeStatement^, array<CodeStatement^>^) | Initializes a new instance of the CodeIterationStatement class using the specified parameters. |
| Name | Description | |
|---|---|---|
![]() | EndDirectives | Gets a CodeDirectiveCollection object that contains end directives.(Inherited from CodeStatement.) |
![]() | IncrementStatement | Gets or sets the statement that is called after each loop cycle. |
![]() | InitStatement | Gets or sets the loop initialization statement. |
![]() | LinePragma | Gets or sets the line on which the code statement occurs. (Inherited from CodeStatement.) |
![]() | StartDirectives | Gets a CodeDirectiveCollection object that contains start directives.(Inherited from CodeStatement.) |
![]() | Statements | Gets the collection of statements to be executed within the loop. |
![]() | TestExpression | Gets or sets the expression to test as the condition that continues the loop. |
![]() | UserData | Gets the user-definable data for the current object.(Inherited from CodeObject.) |
| Name | Description | |
|---|---|---|
![]() | Equals(Object^) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | MemberwiseClone() | |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
A CodeIterationStatement can represent a for loop or while loop.
The InitStatement property specifies the statement to execute before the first loop iteration. The TestExpression property specifies the loop continuation expression, which must evaluate to true at the end of each loop iteration for another iteration to begin. The IncrementStatement property specifies the statement to execute at the end of each loop iteration. The Statements property specifies the collection of statements to execute within the loop.
This example demonstrates using a CodeIterationStatement to represent a for loop.
// Declares and initializes an integer variable named testInt. CodeVariableDeclarationStatement^ testInt = gcnew CodeVariableDeclarationStatement( int::typeid,"testInt",gcnew CodePrimitiveExpression( (int^)0 ) ); array<CodeMethodInvokeExpression^>^writelineparams = {gcnew CodeMethodInvokeExpression( gcnew CodeVariableReferenceExpression( "testInt" ),"ToString",nullptr )}; array<CodeStatement^>^codestatements = {gcnew CodeExpressionStatement( gcnew CodeMethodInvokeExpression( gcnew CodeMethodReferenceExpression( gcnew CodeTypeReferenceExpression( "Console" ),"WriteLine" ),writelineparams ) )}; // Creates a for loop that sets testInt to 0 and continues incrementing testInt by 1 each loop until testInt is not less than 10. // Each loop iteration the value of the integer is output using the Console.WriteLine method. CodeIterationStatement^ forLoop = gcnew CodeIterationStatement( gcnew CodeAssignStatement( gcnew CodeVariableReferenceExpression( "testInt" ),gcnew CodePrimitiveExpression( 1 ) ),gcnew CodeBinaryOperatorExpression( gcnew CodeVariableReferenceExpression( "testInt" ),CodeBinaryOperatorType::LessThan,gcnew CodePrimitiveExpression( 10 ) ),gcnew CodeAssignStatement( gcnew CodeVariableReferenceExpression( "testInt" ),gcnew CodeBinaryOperatorExpression( gcnew CodeVariableReferenceExpression( "testInt" ),CodeBinaryOperatorType::Add,gcnew CodePrimitiveExpression( 1 ) ) ),codestatements ); // A C# code generator produces the following source code for the preceeding example code: // int testInt = 0; // for (testInt = 1; (testInt < 10); testInt = (testInt + 1)) { // Console.WriteLine(testInt.ToString());
Available since 1.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


