Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Operators.

Similar presentations


Presentation on theme: "Relational Operators."— Presentation transcript:

1 Relational Operators

2 Relational Operators Relational operators are the symbols used in the condition to be evaluated in If statements: = = is the same as (the comparison operator) != is not the same as (not equal to) < less than > greater than <= less than or equal to >= greater than or equal to

3 Examples Given: A = 23, B = 16 Then: A > B is true
A < B is false A >= B is true A <= B is false A != B is true A == B is false

4 Comparison vs. Assignment Operators
There is a significant difference between the use of an equals sign (=) as the assignment operator and a double equals sign (==) as the comparison operator. As an assignment operator, the equals sign sets the value of an expression on the right side to the variable on the left side. As a comparison operator, the double equals sign asks the question, “Is the value of the variable on the left side the same as the value of the expression, number, or variable on the right side?” a single equals sign (=) signifies the assignment operator a double equals sign (==) signifies the comparison operator This is demonstrated in the examples that follow in the next slides.

5 The Assignment Operator (review from Chapter 3)
Given: A = 14, B = 27 In programming code, the assignment statement: A = B sets the value of B to the variable A In other words, after this statement is executed, both A = 27 and B = 27. In this case, the equals sign is used as an assignment operator.

6 The Comparison Operator
Given: A = 14, B = 27 Using relational operators, the statement: A == B is a comparison This statement asks the question, “Is the value of A the same as the value of B?” In this case, since A and B have different values, the answer is “no” and the statement would result in a value of False.

7 Any Questions ?


Download ppt "Relational Operators."

Similar presentations


Ads by Google