There are six relational operators:
Type | Operator | Associativity | |||||
Arithmetic | ** | right to left | |||||
* | / | left to right | |||||
+ | - | left to right | |||||
Relational | < | <= | > | >= | == | /= | none |
This means that a relational operator can be evaluated only if its two operands have been evaluated. For example, in
expressions a+b and c*c + d*d are evaluated before the relational operator /= is evaluated.a + b /= c*c + d*d
is equivalent to the following:3.0*SQRT(Total)/(Account + Sum) - Sum*Sum >= Total*GNP - b*b
(3.0*SQRT(Total)/(Account + Sum) - Sum*Sum) >= (Total*GNP - b*b)
In the above, please note the left-to-right evaluation order and the type conversion making 220 to 220.0 before carrying out /=x*x - y*y + 2.0*x*y /= p*q + p**3 - q**3 --> 3.0*3.0 - 7.0*7.0 + 2.0*3.0*7.0 /= 6*2 + 6**3 - 2**3 --> [3.0*3.0] - 7.0*7.0 + 2.0*3.0*7.0 /= 6*2 + 6**3 - 2**3 --> 9.0 - 7.0*7.0 + 2.0*3.0*7.0 /= 6*2 + 6**3 - 2**3 --> 9.0 - [7.0*7.0] + 2.0*3.0*7.0 /= 6*2 + 6**3 - 2**3 --> 9.0 - 49.0 + 2.0*3.0*7.0 /= 6*2 + 6**3 - 2**3 --> [9.0 - 49.0] + 2.0*3.0*7.0 /= 6*2 + 6**3 - 2**3 --> -40.0 + 2.0*3.0*7.0 /= 6*2 + 6**3 - 2**3 --> -40.0 + [2.0*3.0]*7.0 /= 6*2 + 6**3 - 2**3 --> -40.0 + 6.0*7.0 /= 6*2 + 6**3 - 2**3 --> -40.0 + [6.0*7.0] /= 6*2 + 6**3 - 2**3 --> -40.0 + 42.0 /= 6*2 + 6**3 - 2**3 --> [-40.0 + 42.0] /= 6*2 + 6**3 - 2**3 --> 2.0 /= 6*2 + 6**3 - 2**3 --> 2.0 /= [6*2] + 6**3 - 2**3 --> 2.0 /= 12 + 6**3 - 2**3 --> 2.0 /= 12 + [6**3] - 2**3 --> 2.0 /= 12 + 216 - 2**3 --> 2.0 /= [12 + 216] - 2**3 --> 2.0 /= 228 - 2**3 --> 2.0 /= 228 - [2**3] --> 2.0 /= 228 - 8 --> 2.0 /= [228 - 8] --> 2.0 /= [220] --> 2.0 /= 220.0 --> .TRUE.
If you compare characters in different sequences such as 'A' < 'a' and '2' >= 'N', you are asking for trouble since different encoding methods may produce different answers. Moreover, do not assume there exists a specific order among upper and lower case letters, digits, and special symbols. Thus, '+' <= 'A', '*' >= '%', 'u' > '$', and '8' >= '?' make no sense. However, you can always compare if two characters are equal or not equal. Hence, '*' /= '9', 'a' == 'B' and '8' == 'b' are perfectly fine.A < B < C < D < E < F < G < H < I < J < K < L < M < N < O < P < Q < R < S < T < U < V < W < X < Y < Z a < b < c < d < e < f < g < h < i < j < k < l < m < n < o < p < q < r < s < t < u < v < w < x < y < z 0 < 1 < 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9
Here is the method for comparing two strings:
The first three characters of both strings are equal. Since 'd' of the first string is smaller than 'e' of the second, "abcdef" < "abcefg" holds.a b c d e f = = = < a b c e f g
Since all compared characters are equal and the first string is shorter, "01357" < "013579" holds.0 1 3 5 7 = = = = = 0 1 3 5 7 9
The first character (i.e., 'D' < 'F') determines the outcome. That is, "DOG" < "FOX" yields .TRUE.D O G < F O X
"abcde" // "xyz" < "abc" // ("dex" // "ijk") --> ["abcde" // "xyz"] < "abc" // ("dex" // "ijk") --> "abcdexyz" < "abc" // ("dex" // "ijk") --> "abcdexyz" < "abc" // (["dex" // "ijk"]) --> "abcdexyz" < "abc" // ("dexijk") --> "abcdexyz" < "abc" // "dexijk" --> "abcdexyz" < ["abc" // "dexijk"] --> "abcdexyz" < "abcdexijk" --> .FALSE.