Expression Operations

Предыдущая страницаВ началоСледующая страница

The string members can only be subject to the operation concatenate, or, simply, addition of two strings ( + )

"T-FLEX"+" CAD" = T-FLEX CAD

The numerical members are subject to common arithmetic operations, as

addition ( + );

subtraction ( - );

multiplication ( * );

division ( / );

unary negation (minus).

You can't divide by zero. This results in an error.

You can use any number of spaces inside expressions. Spaces sometimes give more visibility.

An important point is the order of operations (priority). For example, the multiplication operation takes precedence over the addition operation. To change the order of operations, use parentheses. Using parentheses correctly avoids unexpected results.

The separator between the integer and fractional parts must be a dot. When entering values in the variable editor and in the command value input fields, an erroneous separator is autocorrect: if a comma was placed instead of a dot separator, autocorrect will be performed.

VariablesEditor54

exponentiation ( ** or ^ )

Example:

2 ** 3  = 8

-3 ** 3 = -27

When performing this operation, errors may occur (for example, an overflow when the result value is too large). If one of these situations occurs, the following message appears:

VariablesEditor55

getting the remainder of the division ( % )

Example:

23 % 5 = 3

23.7 % 5.5 = 1.7

-23 % -5 = -3

23 % -5 = 3

-23 % 5 = -3

The result of the operation member1 % member2 is the remainder of dividing member1 by member2.

The value of member2 may not be zero. In the case member2 = 0, the error occurs, "Division by zero".

VariablesEditor56

Logical operations

Greater than ( > )

Less than ( < )

Greater than or equal ( >= )

Less than or equal ( <= )

Inequality ( != )

Equality ( == )

Logical AND ( && )

Logical OR ( || )

Logical NOT ( ! )

Examples:

23 > 45 && 56 < 34

This example expresses the question: Is the number 23 greater than the number 45 and the number 56 less than the number 34? Obviously, the answer will be - no, therefore the value of this expression is zero.

The expression !VAR_1 is the same as VAR_1 == 0

Logical operations are usually used for comparing the value of a variable against a constant or a value of another variable. A shortcoming here is that only two values are possible as the result of evaluating a logical expression - 0 or 1.

Another form of using logical operations is a conditional statement.

A conditional statement has the following structure:

condition ? value1 : value2

Example:

VAR_1 > 100 ? 1 : -1

If the value of VAR_1 is greater than 100, then the statement will yield 1, otherwise it yields -1.

One can use arbitrary expressions for the condition, value1 and value2.

VAR_1 ? 1 : -1

or, just the same thing,

VAR_1 != 0 ? 1 : -1

VAR_1 != 0 && VAR_2 == 0) ? (VAR_3 + 1) : (VAR_4 -1)

A good example is the select and switch functions, which can be viewed in the corresponding section.