다음을 통해 공유


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 = 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)

설명

A는 CodeIterationStatement 루프 또는 while 루프를 for 나타낼 수 있습니다.

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

생성자

Name Description
CodeIterationStatement()

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

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

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

속성

Name Description
EndDirectives

CodeDirectiveCollection 끝 지시문을 포함하는 개체를 가져옵니다.

(다음에서 상속됨 CodeStatement)
IncrementStatement

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

InitStatement

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

LinePragma

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

(다음에서 상속됨 CodeStatement)
StartDirectives

CodeDirectiveCollection 시작 지시문을 포함하는 개체를 가져옵니다.

(다음에서 상속됨 CodeStatement)
Statements

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

TestExpression

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

UserData

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

(다음에서 상속됨 CodeObject)

메서드

Name Description
Equals(Object)

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

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

기본 해시 함수로 사용됩니다.

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

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

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

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

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

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

(다음에서 상속됨 Object)

적용 대상