课程表

VB.Net基本教程

VB.Net高级教程

工具箱
速查手册

VB.Net - If ... Then语句

当前位置:免费教程 » 程序设计 » VB.Net

它是控制语句的最简单形式,经常用于决策和改变程序执行的控制流程。 if-then语句的语法是:

  1. If condition Then
  2. [Statement(s)]
  3. End If

其中,condition是一个布尔或关系条件,Statement(s)是一个简单或复合语句。 If-Then语句的示例是:

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

如果条件的计算结果为true,那么If语句中的代码块将被执行。 如果条件计算结果为假,则第一组代码在If语句结束后(在结束If之后)将被执行。


流程图:


if语句流程图

示例:

  1. Module decisions
  2. Sub Main()
  3. 'local variable definition
  4. Dim a As Integer = 10
  5. ' check the boolean condition using if statement
  6. If (a < 20) Then
  7. ' if condition is true then print the following
  8. Console.WriteLine("a is less than 20")
  9. End If
  10. Console.WriteLine("value of a is : {0}", a)
  11. Console.ReadLine()
  12. End Sub
  13. End Module

当上述代码被编译和执行时,它产生以下结果:
  1. a is less than 20
  2. value of a is : 10
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号