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)
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. Dim testInt As New CodeVariableDeclarationStatement(GetType(Integer), "testInt", New CodePrimitiveExpression(0)) ' Creates a for loop that sets testInt to 0 and continues incrementing testInt by 1 each loop until testInt is not less than 10. ' initStatement parameter for pre-loop initialization. ' testExpression parameter indicates the epxression to test for continuation condition. ' incrementStatement parameter indicates statement to execute after each iteration. ' statements parameter contains the statements to execute during each interation of the loop. ' Each loop iteration the value of the integer is output using the Console.WriteLine method. Dim forLoop As New CodeIterationStatement( _ New CodeAssignStatement(New CodeVariableReferenceExpression("testInt"), New CodePrimitiveExpression(1)), _ New CodeBinaryOperatorExpression(New CodeVariableReferenceExpression("testInt"), _ CodeBinaryOperatorType.LessThan, New CodePrimitiveExpression(10)), _ New CodeAssignStatement(New CodeVariableReferenceExpression("testInt"), _ New CodeBinaryOperatorExpression(New CodeVariableReferenceExpression("testInt"), _ CodeBinaryOperatorType.Add, New CodePrimitiveExpression(1))), _ New CodeStatement() {New CodeExpressionStatement( _ New CodeMethodInvokeExpression(New CodeMethodReferenceExpression(New CodeTypeReferenceExpression("Console"), "WriteLine"), _ New CodeMethodInvokeExpression(New CodeVariableReferenceExpression("testInt"), "ToString")))}) ' A Visual Basic code generator produces the following source code for the preceeding example code: ' Dim testInt As Integer = 0 ' testInt = 1 ' Do While (testInt < 10) ' Console.WriteLine(testInt.ToString) ' testInt = (testInt + 1)
System.CodeDom.CodeObject
System.CodeDom.CodeStatement
System.CodeDom.CodeIterationStatement
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.