Operators in tcl are same as in other languages like c, c++.
Tcl supports following operators.
Arithmetic Operators (+, - , *, /,%)
Relational Operators(==, !=, < , > , >=)
Bitwise Operators(&,|,^)
Ternary Operators(?:)
Logical Operators(&&, || , !)
Here if we have two variables say x and y
we write in tcl command prompt
set x 10
set y 12
puts c [expr $x +$y] will print c as 22.
similarly we can use relational operators in following manner
while{$x < 13 } {
incr x
puts $ y
}
#Remember syntax.
For Ternary operator we have like c as
expression 1 ? expression 2 : expression 3.
if after evaluating expression 1 , it is true then expression 2 will be evaluated. example
set x 3
set y [expr ($x>4)?"x is greater than 4":"x is less than 4"]
will print " x is less than 4"
No comments:
Post a Comment