CodeIterationStatement クラス

定義

for ステートメント、またはループの続行条件としてテスト式を使用するステートメントのブロックを反復処理するループを表します。Represents a for statement, or a loop through a block of statements, using a test expression as a condition for continuing to loop.

public ref class CodeIterationStatement : System::CodeDom::CodeStatement
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeIterationStatement : System.CodeDom.CodeStatement
type CodeIterationStatement = class
    inherit CodeStatement
Public Class CodeIterationStatement
Inherits CodeStatement
継承
CodeIterationStatement
属性

この例では、for ループを表すために CodeIterationStatement を使用する方法を示します。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());
// 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.
 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)

注釈

CodeIterationStatement は、for ループまたは while ループを表すことができます。A CodeIterationStatement can represent a for loop or while loop.

InitStatement プロパティは、最初のループの反復処理の前に実行するステートメントを指定します。The InitStatement property specifies the statement to execute before the first loop iteration. TestExpression プロパティは、ループ継続式を指定します。これは、別のイテレーションが開始されるたびに、ループの反復処理の最後に true として評価される必要があります。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. IncrementStatement プロパティは、各ループの反復処理の終了時に実行するステートメントを指定します。The IncrementStatement property specifies the statement to execute at the end of each loop iteration. Statements プロパティは、ループ内で実行するステートメントのコレクションを指定します。The Statements property specifies the collection of statements to execute within the loop.

コンストラクター

CodeIterationStatement() CodeIterationStatement クラスの新しいインスタンスを初期化します。Initializes a new instance of the CodeIterationStatement class.
CodeIterationStatement(CodeStatement, CodeExpression, CodeStatement, CodeStatement[])

指定されたパラメーターを使用して、CodeIterationStatement クラスの新しいインスタンスを初期化します。Initializes a new instance of the CodeIterationStatement class using the specified parameters.

プロパティ

EndDirectives

終了ディレクティブを含む CodeDirectiveCollection オブジェクトを取得します。Gets a CodeDirectiveCollection object that contains end directives.

(継承元 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.

(継承元 CodeStatement)
StartDirectives

開始ディレクティブを含む CodeDirectiveCollection オブジェクトを取得します。Gets a CodeDirectiveCollection object that contains start directives.

(継承元 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.

(継承元 CodeObject)

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判定します。Determines whether the specified object is equal to the current object.

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(継承元 Object)
ToString()

現在のオブジェクトを表す string を返します。Returns a string that represents the current object.

(継承元 Object)

適用対象