EGL Reference Guide for iSeries


Operators and precedence

The next table lists the EGL operators in order of decreasing precedence. Except for the unary plus (+), minus (-), and not (!), each operator works with two operands.


Operators (separated by commas) Type of operator Meaning
+, - Numeric, unary Unary plus (+) or minus (-) is a sign before an operand or parenthesized expression, not an operator between two expressions.
*, /, % Numeric Multiplication (*) and integer division (/) are of equal precedence. The division of integers retains a fractional value, if any; for example, 7/5 yields 1.4.

% is the remainder operator, which resolves to the modulus when the first of two operands or numeric expressions is divided by the second; for example, 7%5 yields 2.

If you need to ensure that arithmetic results are consistent between EGL output in Java and COBOL, avoid using the remainder operator.

+, - Numeric Addition (+) and subtraction (-) are of equal precedence.
= Numeric or string = is the assignment operator, which copies a numeric or character value from an expression or operand into an operand.
! Logical, unary ! is the not operator, which resolves to a Boolean value (true or false) opposite to the value of a logical expression that immediately follows. That subsequent expression must be in parentheses.
=, != , <, >, <=, >=, in, is, not Logical for comparison The logical operators used for comparison are of equal precedence and are described in the page on logical expressions. Each operator resolves to true or false.
&& Logical && is the and operator, which means "both must be true." The operator resolves to true if the logical expression that precedes the operator is true and if the logical expression that follows the operator is true; otherwise, && resolves to false.
|| Logical || is the or operator, which means "one or the other or both." The operator resolves to true if the logical expression that precedes the operator is true or if the logical expression that follows the operator is true or if both are true; otherwise || resolves to false.

You may override the usual precedence (also called the order of operations) by using parentheses to separate one expression from another. Operations that have the same precedence in an expression are evaluated in left-to-right order.

The equal sign (=) is used in two ways:


Related reference
Items
in
Logical expressions
Numeric expressions
Primitive types
String expressions


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]