Visual Basic If…Then 语句
If…Then 是条件语句的最简单形式,经常用于判断条件和更改程序执行的流程。if-then 语句的语法为:
If condition Then[Statement(s)]End If
其中,condition 是布尔或关系条件,Statement(s) 是简单或复合语句。If-Then 语句的一个例子如下:
If (a <= 20) Thenc= c+1End If
如果条件评估为 True,那么 If 语句内的代码块将被执行。如果条件计算结果为 False,那么将执行 If 语句结束后的第一组代码(在关闭 End If 之后)。
流程图

实例
Module decisionsSub Main()'local variable definitionDim 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 IfConsole.WriteLine("value of a is : {0}", a)Console.ReadLine()End SubEnd Module
结果如下:
a is less than 20value of a is : 10