Tcl - Ternary Operator



Operator Description Example
? : Ternary If Condition is true? Then value X : Otherwise value Y

Example

Try the following example to understand ternary operator available in Tcl language −

#!/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"

When you compile and execute the above program it produces the following result −

Value of b is 30

Value of b is 20
tcl_operators.htm
Advertisements