×

VB.Net基本教程

VB.Net 环境设置VB.Net 程序结构VB.Net 基本语法VB.Net 数据类型VB.Net 变量VB.Net 常数和枚举VB.Net 修饰符VB.Net 声明VB.Net 指令VB.Net 运算符VB.Net 决策VB.Net 循环VB.Net 字符串VB.Net 日期和时间VB.Net 数组VB.Net 集合VB.Net 函数VB.Net Sub过程(子程序)VB.Net 类与对象VB.Net 异常处理VB.Net 文件处理VB.Net 基本控制VB.Net 对话框VB.Net 高级表单VB.Net 事件处理

VB.Net 高级教程

VB.Net 正则表达式VB.Net 数据库访问VB.Net Excel工作表VB.Net 发送邮件VB.Net XML处理VB.Net Web编程

VB.Net 有用的资源

VB.Net 有用资源

VB.Net If ... Then语句


VB.Net  决策VB.Net 决策


它是控制语句的最简单形式,经常用于决策和改变程序执行的控制流程。 vbnet-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之后)将被执行。

流程图:


vbnet-if语句流程图

示例:

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

        ' check the boolean condition using vbnet-if statement 
        If (a < 20) Then
            ' vbnet-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 决策


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)