サーチ…


if / elseステートメント

If condition Then 
    code to execute if true
ElseIf condition Then
    code
Else
    code to execute if conditions are both false
End If

forループ

For I as Integer = 1 To 10 Step 1
    code to execute
Next

ステップはオプションで、ステップ1がデフォルトです。ステップはカウントする方法を指示するので、-1は毎回1を減算し、ステップ5はループを通過するたびに5を加算します。

ループを停止する必要がある場合は、次の例のようにExit Forステートメントを使用できます。

Dim iIndex as integer

For I as Integer = 1 To 10 Step 1

Debug.Print  I     
iIndex = I * 10

If iIndex > 90 Then
    Exit For
End If

Loop

ここでは、iIndexが90に達したときにプロセスが停止するように指示したため、1から10を出力する代わりに、9で停止します。

Do Loop

Visual Basicのもう1つの一般的なタイプのループは、停止するように指示されるまでコードの一部を継続的に実行するDO loopです。索引を使用してプロセスを停止する他のループとは異なり、この特定のループでは、停止するように指示する必要があります。

ループを示す簡単な例は次のとおりです

Dim iIndex1 As Integer
iIndex1 = 1
   
Do
   Debug.Print iIndex1 
   iIndex1 = iIndex1 + 1

   If iIndex1 = 10 Then
      Exit Do
   End If
Loop

上記のコードはIndexをとり、1に初期化してインクリメントします。 Debug.Printは、インデックスを印刷してループをラックにDebug.Printするのに役立ちます。各ループで、コードはインデックスが10に達したかどうかを確認し、条件が真である場合にのみExit Doが実行され、ループが停止します。

ケースステートメントの選択

    Dim number As Integer = 8
    Select Case number
        Case 1 To 5
            Debug.WriteLine("Between 1 and 5, inclusive")
            ' The following is the only Case clause that evaluates to True.
        Case 6, 7, 8
            Debug.WriteLine("Between 6 and 8, inclusive")
        Case 9 To 10
            Debug.WriteLine("Equal to 9 or 10")
        Case Else
            Debug.WriteLine("Not between 1 and 10, inclusive")
    End Select


Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow