- 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 - 集合
- 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 - Excel 表格
- VB.Net - 傳送電子郵件
- VB.Net - XML 處理
- VB.Net - Web 程式設計
- VB.Net 實用資源
- VB.Net - 快速指南
- VB.Net - 實用資源
- VB.Net - 論壇
VB.Net - 巢狀 If 語句
在 VB.Net 中,巢狀 If-Then-Else 語句始終是合法的,也就是說可以在另一個 If ElseIf 語句內使用一個 If 或 ElseIf 語句。
語法
巢狀 If 語句的語法如下所示 -
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 If
End If
你巢狀 If 語句的方式與巢狀 ElseIf...Else 的方式類似。
示例
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 Sub
End Module
當以上程式碼被編譯並執行後,會生成以下結果 -
Value of a is 100 and b is 200 Exact value of a is : 100 Exact value of b is : 200
vb.net_decision_making.htm
廣告