This chapter describes some conventional operators (>, <, =), but also several that operate on strings, as well as some different symbols for logical AND and OR operations. Check the summary at the end of the chapter, and if necessary review the descriptions of those operators that remain unclear.
In the preceding chapter we considered arithmetic expressions that allow us to set the value of a variable or to perform calculations using variables as constants. In many computing applications, however, we need to test a relationship between two variables and take differing actions depending on the result of the test. All computer languages have some way to perform tests of this type. (In fact, the ability to test and then branch to different instructions based on the result is the real secret to the power of computers.) In M, there are several different types of comparisons and operations that can assist in this process. These operators will be considered in this chapter.
Arithmetic relational and string relational operators
Since M stores variables as strings, a distinction must be made between the value of numeric strings and other strings, since some numbers may be expressed in several different ways. The numbers 35, 3.5E1, and .35E2, for example, are all equivalent, but they are stored in different ways. To test numeric relationships, two operators are available:
Operator
Meaning
<
Less than
>
Greater than
When these operators are invoked, the variables are first...
Copyright Butterworth-Heinemann 1997 under license agreement with Books24x7