Tcl-tk-tcl-ternary-operator

提供:Dev Guides
移動先:案内検索

Tcl-三項演算子

Operator Description Example
? : Ternary If Condition is true? Then value X : Otherwise value 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