TCL三元运算符

在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

联系我们

邮箱 626512443@qq.com
电话 18611320371(微信)
QQ群 235681453

Copyright © 2015-2022

备案号:京ICP备15003423号-3