课程表

VB.Net基本教程

VB.Net高级教程

工具箱
速查手册

VB.Net - 嵌套If语句

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

在VB.Net中总是合法的嵌套If-Then-Else语句,这意味着您可以在另一个If ElseIf语句中使用一个If或ElseIf语句。


语法:

  1. If( boolean_expression 1)Then
  2. 'Executes when the boolean expression 1 is true
  3. If(boolean_expression 2)Then
  4. 'Executes when the boolean expression 2 is true
  5. End If
  6. End If
您可以嵌套ElseIf ... Else的方式,与嵌套If语句类似。


示例:

  1. Module decisions
  2. Sub Main()
  3. 'local variable definition
  4. Dim a As Integer = 100
  5. Dim b As Integer = 200
  6. ' check the boolean condition
  7. If (a = 100) Then
  8. ' if condition is true then check the following
  9. If (b = 200) Then
  10. ' if condition is true then print the following
  11. Console.WriteLine("Value of a is 100 and b is 200")
  12. End If
  13. End If
  14. Console.WriteLine("Exact value of a is : {0}", a)
  15. Console.WriteLine("Exact value of b is : {0}", b)
  16. Console.ReadLine()
  17. End Sub
  18. End Module

当上述代码被编译和执行时,它产生以下结果:
  1. Value of a is 100 and b is 200
  2. Exact value of a is : 100
  3. Exact value of b is : 200
转载本站内容时,请务必注明来自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号