Share via


CodeIterationStatement 클래스

정의

테스트 식을 반복 조건으로 사용하여 for 문 또는 문의 블록을 통한 루프를 나타냅니다.

public ref class CodeIterationStatement : System::CodeDom::CodeStatement
public class CodeIterationStatement : System.CodeDom.CodeStatement
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeIterationStatement : System.CodeDom.CodeStatement
type CodeIterationStatement = class
    inherit CodeStatement
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeIterationStatement = class
    inherit CodeStatement
Public Class CodeIterationStatement
Inherits CodeStatement
상속
CodeIterationStatement
특성

예제

이 예제에서는 를 사용하여 CodeIterationStatement 루프를 나타내는 방법을 보여 줍니다 for .

// 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 루프 또는 while 루프를 for 나타낼 수 있습니다.

속성은 InitStatement 첫 번째 루프 반복 전에 실행할 문을 지정합니다. 속성은 루프 연속 식을 지정합니다. 이 식은 TestExpression 다른 반복이 시작되도록 각 루프 반복의 끝에서 로 계산 true 해야 합니다. 속성은 IncrementStatement 각 루프 반복의 끝에서 실행할 문을 지정합니다. 속성은 Statements 루프 내에서 실행할 문의 컬렉션을 지정합니다.

생성자

CodeIterationStatement()

CodeIterationStatement 클래스의 새 인스턴스를 초기화합니다.

CodeIterationStatement(CodeStatement, CodeExpression, CodeStatement, CodeStatement[])

지정된 매개 변수를 사용하여 CodeIterationStatement 클래스의 새 인스턴스를 초기화합니다.

속성

EndDirectives

끝 지시문이 포함된 CodeDirectiveCollection 개체를 가져옵니다.

(다음에서 상속됨 CodeStatement)
IncrementStatement

각 루프 주기 다음에 호출되는 문을 가져오거나 설정합니다.

InitStatement

루프 초기화 문을 가져오거나 설정합니다.

LinePragma

코드 문이 있는 줄을 가져오거나 설정합니다.

(다음에서 상속됨 CodeStatement)
StartDirectives

시작 지시문이 포함된 CodeDirectiveCollection 개체를 가져옵니다.

(다음에서 상속됨 CodeStatement)
Statements

루프 내에서 실행되는 문의 컬렉션을 가져옵니다.

TestExpression

루프를 계속할 조건으로 테스트할 식을 가져오거나 설정합니다.

UserData

현재 개체에 대해 사용자 정의 가능한 데이터를 가져옵니다.

(다음에서 상속됨 CodeObject)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상