7.3 Relational OperatorsRelational operators are used to compare two values and then return a Boolean (i.e., true or false). The greater-than operator (>), for example, returns true if the value on the left of the operator is greater than the value on the right. Thus, 5>2 returns the value true, while 2>5 returns the value false. The relational operators for VB.NET are shown in Table 7-1. This table assumes two variables : bigValue and smallValue, in which bigValue has been assigned the value 100 and smallValue the value 50. Table 7-1. Relational operators (assumes bigValue = 100 and smallValue = 50)
Each of these relational operators acts as you might expect. Notice that some of the operators are composed of two characters . For example, the greater than or equal to operator is created using the greater than symbol ( > ) and the equal sign ( = ). Notice that you can place these symbols in either order ( >= or => ) to form the greater than or equal to operator. In VB.NET, the equality operator and the assignment operator are represented by the same symbol, the equal sign ( = ). In the following code line, the symbol is used in each of these ways: If myX = 5 Then myX = 7 The first use of the = symbol is as the equality operator ("if myX is equal to 5"); the second use is as the assignment operator ("set myX to the value 7"). The compiler figures out how the symbol is to be interpreted according to the context. |