Using Operators ColdFusion Help

Operators are the building blocks of expressions. They enable you to combine simple values other expressions into new expressions that return values. The four types of operators based on the values they return are shown in the following list:

Arithmetic Returns a number
String Returns a string
Decision/comparison Returns a Boolean value
Boolean Returns a Boolean value

Arithmetic Operators

ColdFusion has nine arithmetic operators: the four basic mathematical operators of addition subtraction multiplication and division plus five other operators.

The four basic operators are outlined in Table 6.2

TABLE·6.2:

TABLE·6.2:

The remaining operators can be classified into two groups: binary operators (those that require two values to work) and unary operators (those that require one value to work).

Binary Arithmetic Operation 

The three binary arithmetic operators are described in the’ following list

Returns the modulus (remainder) of an integer division operation. For instance S divided by 3 returns 1 with a remainder of 2. In this case, 5 MOO 3 returns 2. Remember you can’t divide by zero; therefore, 5 MOO 0 is invalid.

Returns the result of integer division. That is, two integers are divided and the result (not the remainder) is returned. Therefore S\3 returns 1.Again, division by zero is not possible, making 5\0 invalid.

Raises one number to the power of another. For instance, 5″3 returns the value of S3, or 125.

Unary Arithmetic Operators

There are two unary arithmetic operators used to set the sign of a number: + and – For instance +2 is positive 2 and -2 is negative 2 or (-1) It is rare to see the + operator in use but the – operator is seen whenever a negative number.i s indicated and also when the varue contained in a variable is negated: -VariableName

String Operators

ColdFusion supports one string operation: concatenation. This operation is indicated by the & operator.

Concatenation is the closest process to addition when working with string values. Concatenation combines two string values into a single string. For instance He110′ &  world” results in the value “Hel 10 world”

Decision/Comparison Operators

Decision operators, which are also called comparison operators are used to compare two values or expressions and to return a Boolean value of True or False based on a criterion for comparing the two values. As you will see in Chapter 7 “Controlling the Flow of Your Templates,” these expressions are commonly used in decision-making for the CFIF tag. The eight decision operators in ColdFusion are described in Table 6.3;

TAB l E 6. 3:

TAB l E 6. 3:

TAB L E 6. 3:

TAB L E 6. 3:

Boolean Operators

Both decision/ comparison operators and Boolean operators return Boolean values. However, decision/ comparison operators are generally used on non-Boolean values. Boolean operators can be used only on Boolean values. *

There”are six Boolean operators that work with one or two Boolean values and return  a Boolean value as a result:

• NOT
• AND
• OR
• XOR
• EQV
• IMP

NOT

NOT is a unary Boolean operator that reverses a value from True to False or from False to True (see Table 6.4).

TAB L E 6. 4

TAB L E 6. 4

AND

AND is a binary Boolean operator that returns True only when both values are True (see Table 6.5).

TABLE 6.5:

TABLE 6.5:

OR

OR is a binary Boolean operator that returns True when ‘either value is True or both are True (see Table 6.6)

TABLE 6.6:

TABLE 6.6:

XOR

XOR is a binary Boolean operator (commonly known as an exclusive OR)that returns True only when either value is True but not when both are True (see Table 6.7).

TABLE 6.7:

TABLE 6.7:

EQV

EQV is a binary operator (commonly known as equivalence) that returns True when both values are True or when bot’. values are False (see Table 6.8) .

TABLE 6.8:

TABLE 6.8:

IMP

IMP is a binary operator (commonly known as implication) that returns True when the statement If X then Y is True. This statement is True except when Xis True and Y is False (see Table 6.9).

TABLE 6.9:

TABLE 6.9:

Posted on November 14, 2015 in Writing Expression

Share the Story

Back to Top
Share This