Tcl-tk-tcl-ternary-operator

提供:Dev Guides
2020年6月23日 (火) 07:45時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

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