VB.Net 教程:If … Then语句

返回到:VB.Net – 决策

它是控制语句的最简单形式,经常用于决策和改变程序执行的控制流程。 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语句中的代码块将被执行。 如果条件计算结果为假,则第一组代码在If语句结束后(在结束If之后)将被执行。

流程图:

VB.Net 教程:If ... Then语句

示例:

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 – 决策

作者:terry,如若转载,请注明出处:https://www.web176.com/vbnet_api/11419.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2023年3月1日
下一篇 2023年3月1日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注