Tcl - 三元运算符



运算符 描述 示例
? : 三元 如果条件为真?则为值 X:否则为值 Y

示例

尝试以下示例了解 Tcl 语言中提供的三元运算符 −

#!/usr/bin/tclsh

set a 10;
set b [expr $a == 1 ? 20: 30]
puts "Value of b is $b\n"
set b [expr $a == 10 ? 20: 30]
puts "Value of b is $b\n" 

当你编译并执行上述程序时,它会产生以下结果 −

Value of b is 30

Value of b is 20
tcl_operators.htm
广告
© . All rights reserved.