在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 物聯(lián)網(wǎng)/ Tcl if...else語句
TCL內(nèi)置函數(shù)
TCL變量
TCL嵌套循環(huán)
TCL決策
TCL循環(huán)
Tcl if...else語句
Tcl教程
TCL字符串
TCL邏輯運算符
TCL Switch語句
TCL列表
TCL運算符優(yōu)先級
TCL數(shù)據(jù)類型
TCL環(huán)境設(shè)置
TCL正則表達式
TCL命名空間
TCL運算符
TCL特殊變量
TCL數(shù)組
TCL算術(shù)運算符
Tcl For循環(huán)
TCL文件I/O
TCL關(guān)系運算符
TCL if語句
TCL命令
TCL基本語法
TCL三元運算符
TCL continue語句
TCL嵌套if語句
TCL字典
TCL break語句
TCL包
TCL 嵌套switch語句
TCL while循環(huán)
TCL位運算符
TCL過程
TCL錯誤處理

Tcl if...else語句

if語句可以跟著一個可選的else語句,else語句塊執(zhí)行時,布爾表達式是假的。

語法

在Tcl語言的if ... else語句的語法是:

if {boolean_expression} {
  # statement(s) will execute if the boolean expression is true 
} else {
  # statement(s) will execute if the boolean expression is false
}

如果布爾表達式的值為true,那么if代碼塊將被執(zhí)行,否則else塊將被執(zhí)行。

TCL語言使用expr內(nèi)部命令,因此它不是明確地使用expr語句所需的。

流程圖

If Else Statement

示例

#!/usr/bin/tclsh

set a 100

#check the boolean condition 
if {$a < 20 } {
   #if condition is true then print the following 
   puts "a is less than 20"
} else {
   #if condition is false then print the following 
   puts "a is not less than 20"
}
puts "value of a is : $a"

當上述代碼被編譯和執(zhí)行時,它產(chǎn)生了以下結(jié)果:

a is not less than 20;
value of a is : 100

if...else if...else 語句

if語句可以跟著一個可選的else if ... else語句,使用單個if 測試各種條件if...else if 聲明是非常有用的。

當使用if , else if , else語句有幾點要記?。?/p>

  • 一個if可以有零或一個else,它必須跟在else if之后。

  • 一個if語句可以有零到多個else if,并且它們必須在else之前。

  • 一旦一個 else if 成功,任何剩余else if 或else 不會再被測試。

語法

Tcl語言的 if...else if...else語句的語法是:

if {boolean_expression 1} {
   # Executes when the boolean expression 1 is true
} elseif {boolean_expression 2} {
   # Executes when the boolean expression 2 is true 
} elseif {boolean_expression 3} {
   # Executes when the boolean expression 3 is true 
} else {
   # executes when the none of the above condition is true 
}

示例

#!/usr/bin/tclsh

set a 100

#check the boolean condition
if { $a == 10 } {
   # if condition is true then print the following 
   puts "Value of a is 10"
} elseif { $a == 20 } {
   # if else if condition is true 
   puts "Value of a is 20"
} elseif { $a == 30 } {
   # if else if condition is true 
   puts "Value of a is 30"
} else {
   # if none of the conditions is true 
   puts "None of the values is matching"
}

puts "Exact value of a is: $a"

當上述代碼被編譯和執(zhí)行時,它產(chǎn)生了以下結(jié)果:

None of the values is matching
Exact value of a is: 100