在VB.Net中总是合法的嵌套If-Then-Else语句,这意味着您可以在另一个If ElseIf语句中使用一个If或ElseIf语句。
语法:
If( boolean_expression 1)Then 'Executes when the boolean expression 1 is true If(boolean_expression 2)Then 'Executes when the boolean expression 2 is true End IfEnd If
您可以嵌套ElseIf ... Else的方式,与嵌套If语句类似。示例:
Module decisions Sub Main() 'local variable definition Dim a As Integer = 100 Dim b As Integer = 200 ' check the boolean condition If (a = 100) Then ' if condition is true then check the following If (b = 200) Then ' if condition is true then print the following Console.WriteLine("Value of a is 100 and b is 200") End If End If Console.WriteLine("Exact value of a is : {0}", a) Console.WriteLine("Exact value of b is : {0}", b) Console.ReadLine() End SubEnd Module
当上述代码被编译和执行时,它产生以下结果:
Value of a is 100 and b is 200Exact value of a is : 100Exact value of b is : 200
转载本站内容时,请务必注明来自W3xue,违者必究。


优化或报错有奖
皖公网安备34020702000426号