Vb.net-if-statements

提供:Dev Guides
移動先:案内検索

VB.Net-If …​ Thenステートメント

これは最も単純な形式の制御ステートメントであり、プログラム実行の制御フローの決定や変更に頻繁に使用されます。 if-thenステートメントの構文は-

If condition Then
[Statement(s)]
End If

ここで、_condition_はブールまたは関係条件であり、Statement(s)は単純または複合ステートメントです。 If-Thenステートメントの例は-

If (a <= 20) Then
   c= c+1
End If

条件がtrueと評価されると、Ifステートメント内のコードブロックが実行されます。 条件がfalseと評価された場合、Ifステートメントの終了後(終了End Ifの後)の最初のコードセットが実行されます。

流れ図

VB.Net ifステートメント

Module decisions
   Sub Main()
      'local variable definition
      Dim a As Integer = 10

      ' check the boolean condition using if statement
      If (a < 20) Then
         ' if condition is true then print the following
         Console.WriteLine("a is less than 20")
      End If
      Console.WriteLine("value of a is : {0}", a)
      Console.ReadLine()
    End Sub
End Module

上記のコードをコンパイルして実行すると、次の結果が生成されます-

a is less than 20
value of a is : 10