Saturday, 22 August 2015

Tool command Language - Lecture 3 ( Operators )

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

Grammar Mistakes in Technical Paper Writing

Let me share some experience in this post with you. I'm currently in the second year of my Ph.D. program. We are in the middle of paper...