CodeIterationStatement Class
Assembly: System (in system.dll)
[SerializableAttribute] [ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] [ComVisibleAttribute(true)] public class CodeIterationStatement : CodeStatement
/** @attribute SerializableAttribute() */ /** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ /** @attribute ComVisibleAttribute(true) */ public class CodeIterationStatement extends CodeStatement
SerializableAttribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) ComVisibleAttribute(true) public class CodeIterationStatement extends CodeStatement
Not applicable.
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 = new CodeVariableDeclarationStatement(typeof(int), "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. CodeIterationStatement forLoop = new CodeIterationStatement( // initStatement parameter for pre-loop initialization. new CodeAssignStatement( new CodeVariableReferenceExpression("testInt"), new CodePrimitiveExpression(1) ), // testExpression parameter to test for continuation condition. new CodeBinaryOperatorExpression( new CodeVariableReferenceExpression("testInt"), CodeBinaryOperatorType.LessThan, new CodePrimitiveExpression(10) ), // incrementStatement parameter indicates statement to execute after each iteration. new CodeAssignStatement( new CodeVariableReferenceExpression("testInt"), new CodeBinaryOperatorExpression( new CodeVariableReferenceExpression("testInt"), CodeBinaryOperatorType.Add, new CodePrimitiveExpression(1) )), // 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. new CodeStatement[] { new CodeExpressionStatement( new CodeMethodInvokeExpression( new CodeMethodReferenceExpression( new CodeTypeReferenceExpression("Console"), "WriteLine" ), new CodeMethodInvokeExpression( new CodeVariableReferenceExpression("testInt"), "ToString" ) ) ) } ); // 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());
// Declares and initializes an integer variable named testInt.
CodeVariableDeclarationStatement testInt = new
CodeVariableDeclarationStatement(int.class.ToType(),
"testInt", new CodePrimitiveExpression((Int32)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.
CodeIterationStatement forLoop = new CodeIterationStatement(
// initStatement parameter for pre-loop initialization.
new CodeAssignStatement(new CodeVariableReferenceExpression(
"testInt"),new CodePrimitiveExpression((Int32)1)),
// testExpression parameter to test for continuation condition.
new CodeBinaryOperatorExpression(new
CodeVariableReferenceExpression("testInt"),
CodeBinaryOperatorType.LessThan, new CodePrimitiveExpression(
(Int32)10)),
// incrementStatement parameter indicates statement to execute after
// each iteration.
new CodeAssignStatement(new
CodeVariableReferenceExpression("testInt"), new
CodeBinaryOperatorExpression(new
CodeVariableReferenceExpression("testInt"),
CodeBinaryOperatorType.Add, new CodePrimitiveExpression((Int32)1))),
// 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.
new CodeStatement[] { new CodeExpressionStatement(new
CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new
CodeTypeReferenceExpression("Console"), "WriteLine"),
new CodeExpression [] { new CodeMethodInvokeExpression(new
CodeVariableReferenceExpression("testInt"), "ToString",
new CodeExpression[] {}) })) });
// A VJ# 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(System.Convert.ToString(testInt));
System.CodeDom.CodeObject
System.CodeDom.CodeStatement
System.CodeDom.CodeIterationStatement
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.