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之后)。

流程图

示例

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

上一篇: VB.Net决策结构 下一篇: VB.Net循环