Comparing values

1.  How to compare values

First I will explain to you how you can compare values. This part (comparing values) is basis and introduction to loops. Comparing two or more variables involves using relation operators. Since all computer information is based on the numerical values and represented by them, comparing the numerical values is the essence of practically all decision making in computer technology. We can six fundamental operators for comparing two values available, and these operators are:
less than
greater than
equal to
less than or equal to
greater than or equal to
not equal to

Each of these operators compares the values of two operands and returns one of the two possible values of type bool : true if the comparison is true, or false if it is not. Now we will see how this comparing operators works with few examples.

Example of value comparison

In this example you will define two variables, and use some of the comparing operators to compare these values. Let’s say that we have two variables a and b. The values of these variables are:
a = 55;
b = 10;
If we use the following comparing operator a > b the program will return the value true, because the variable a has bigger value of a variable b (55 > 10). If we use this operator a < b then the program will return the false value. If a !=  b then the result will be true and if a = b then the result is false because the 55 is not equal to 10.
I hope that you from this example get the general idea of how comparing operators works. It’s not that difficult.


ASCII is a standard for American Standard Code for Information Interchange. Computer technology can only understand and communicate with numbers, so an ASCII code is the numerical representation of all symbolic characters. ASCII was developed a long time ago and now the non-printing characters are rarely used for their original purpose.

The purpose of presenting this ASCII code is to show you how that you can declare variables not only as numbers but as a letters form and alphabet. Assume that you have defined the following variables:
char x = ‘A’, char y = ‘z’;
Now we will apply the comparing operators:
x == 100;
x > y;
x != y;
If the program runs the first line (x == 100) the return value will be false. The reason for this is that every symbol or a letter is transformed into ASCII code and then the binary code. Since humans developed ASCII code which enables us and computers to transform the letters into numbers all of these expressions involve comparing the ASCII code values. In ASCII code the value of an A in decimal system is 65 (look at the previous picture). So the comparison of the value x and number 65 is correct and the return value is true. The second comparison x > y is false because if we transform the symbols A and z into ASCII code we will get the following numbers in decimal system:
·         For A the value in ASCII code is 65 and
·         For z the value in ASCII code is 122.
Since the comparison of variables says that the variable x is greater than y the return value will be false because 65 cannot be greater than 122. For the final comparison is x != y the return value will be true because x is not equal to y or 65 is not equal to 122.
Share on Google Plus