In Computer Upper Case Letter
65 A
66 B
67 C
68 D
69 E
70 F
71 G
72 H
73 I
74 J
75 K
76 L
77 M
78 N
79 O
80 P
81 Q
82 R
83 S
84 T
85 U
86 V
87 W
88 X
89 Y
90 Z
 
In Computer Lower Case Letter
97 a
98 b
99 c
100 d
101 e
102 f
103 g
104 h
105 i
106 j
107 k
108 l
109 m
110 n
111 o
112 p
113 q
114 r
115 s
116 t
117 u
118 v
119 w
120 x
121 y
122 z
 
In Computer Digit
48 0
49 1
50 2
51 3
52 4
53 5
54 6
55 7
56 8
57 9
Introduction To Programming
10-152-310

Learning Plan 3 : Math and Operators

Relational Operators

Is it bigger, smaller, or the same?

Operator Function
< Less Than test
> Greater Than test
<= Less Than or Equal To test
>= Greater Than or Equal To test

Using the Relational Operators

These operators are also used in "if" and "while" statements.

        
        

Relational Boolean Expressions

Relational operators also make boolean expressions that are either true or false.

Testing Relationships

        
        

        

Is 10 less than 10?

        
		

        

This means "Is 10 less than OR equal to 10", which is true.

        
		

        

What about strings? Can we use this for strings and how would it make any sense?

        
        

        

Yes, it makes sense to compare the relationships of strings. Everything in the computer is a number, even characters like "A". Here's a chart showing the numbers in the computer for characters: What Are Characters?

        
        

        

This is why "Fred" with an upper case "F" is smaller than "fred". All upper case letters are smaller than all lower case letters.

        
        

        

Less Than (<)

Is the first value smaller than the second? Relationship testing is done very often in our code, especially in repetition.

Numbers. Most of the time we compare numbers with "less than".

        
        

        

This one catches people sometimes.

        
        

        

We can also use < with strings. This will compare the numeric values of the strings. This can be very useful in some circumstances.

        
        

        

It works with larger strings, too. It will compare each character from left to right until it finds a difference or it reaches the end. Since the upper case "R" has a lower numeric value than the "r" this returns "true".

        
        

        

Comparing string and numbers? Yes! It does type conversion for us. Isn't that a problem?

        
        

		

Greater Than (>)

Is the first value bigger than the second value? Numbers. We frequently want to compare if some value is bigger than another. For example, is the new salary bigger than the maximum salary for that position?

        
        

        

Another example showing floating point numbers.

        
        

        

This also works with strings.

        
        

        

Less Than or Equal To (<=)

Is the first value smaller than or equal to the first value? Adding an equal sign changes the meaning subtly. This can cause some subtle bugs, too. We now have two questions to ask when we read a statement. First: "Is the first value smaller than the second value?". Second: "Is the first value the same as the second value?". If either of the questions is true then the result will be true.

Here's the same one from the less than section with the added equal sign. It's true now because 10 is equal to 10. A way to read this would be, "Is 10 the same or smaller than 10?". Yes, it is.

        
        

        

This one has the same result as above.

        
        

        

It works with strings, just like we thought it would.

        
        

        

One situation that can be tricky is when using variables. What if we really meant that when "count" was 10 the result should be false? It is not immediately obvious that we've made a mistake. This becomes an issue when we get to repetition and looping.

        
        

        

Greater Than or Equal To (>=)

Is the first value bigger than or equal to the second value? Just like the opposite operator this ones work like > with another question added to the test. With this example, the first question is false but the second question is true. First: "Is 10 greater than 10?". Second: "Is 10 equal to 10?". If either of the questions if true then the results is true.

        
        

        

Do either of these need the second question?

        
        

        

Strings too.

        
        

        

How do we avoid auto-conversion?

All relational operators perform type auto-conversion. We have to use discipline and always convert entered data from the prompt dialog to numbers (Number()).