Colorado State University

CS160: Foundations in Programming: Summer 2016


Logical and Comparison Operators


Comparison Operators

Here is a list of the comparison operators that can be used in conditions:
    >     (greater than)
    <     (less than)
    ==    (equals)
    !=    (not equal to)
    <=    (less than or equal to)
    >=    (greater than or equal to)

Please note that the test for equality consists of two equals signs, rather than one. Rememeber that
  x = y;
 
means that x becomes equal to y. But the expression:
  x == y
 
means a test to see if x is equal to y.

Logical Operators

Suppose we want to test more than one thing at once. The and , or , and not are logical operators using in composing the conditional expressions. The complete list of logical operators is:
   &&   (and)
   ||   (or)
   !    (not)   
 

© 2016 CS160 Colorado State University. All Rights Reserved.