Script Operators and Conditions

Operators and conditions are components of statements. Arithmetic operators manipulate the values of numbers. "String operators" work on text strings. Conditional operators compare the values of strings and numbers in IF statements. Compound conditions are built with logical operators. Special operators are used in specific situations.

Arithmetic Operators

Use the arithmetic operators in assignment statements to perform arithmetic on numbers. The arithmetic operators do not function inside strings or conditions.

+

addition

add two numbers

-

subtraction

subtract one number from another

*

multiplication

multiply two number

/

division

divide one number by another

String Operators

+

concatenation

join two strings (not inside double quotation  marks)

.

concatenation

denote the end of a variable name inside double quotes

Conditional Operators

To control execution of a statement or a set of statements based on the value of a variable, use an IF statement with a condition. A condition compares the values of two variables or a variable and a literal number or literal string.

All operators are binary, and the general syntax is A operator B.

If both operand A and operand B are integers, comparison is based on their numerical values. Otherwise, an alphabetic comparison is made.

All string comparisons are case-sensitive. That means "salt" is not equal to "SALT".

Numbers and Strings

=

equality

numbers or strings are equal

<>

inequality

numbers or strings are not equal

Numbers

>

greater than

A is greater than B

<

less than

A is less than B

>=

greater than or equal

A is greater than or equal to B

<=

less than or equal

A is less than or equal to B

Strings

INCL

includes

string A includes string B

NOTINCL

does not include

nstring A does not include string B

Example 1

_s = "string"

IF _s = "string"             \* True

IF _s = "string "            \* False

IF _s = "STRING"             \* False

IF _s INCL "ring"            \* True

IF _s INCL "Ring"            \* False

IF _s NOTINCL "cow"          \* True

Example 2

_var1 = 10

_var2 = 5 + 5

IF _var2 = _var1             \* True

IF _var2 <> _var1            \* False

IF _var1 > 0                 \* True

IF _var2 < 4                 \* False

IF _var1 >= 10               \* True

IF _var1 <= 10               \* True

Compound Conditions

Compound conditions may be formed from multiple conditions using logical operators. Use parentheses to group and nest conditions up to eight levels deep.

AND

logical and

both A and B

OR

logical or

either A or B or both

XOR

exclusive or

either A or B, but not both

Example:

_answers = 42

_dformat = "bib"

IF ((_answers < 100) AND (_dformat = "bib"))    /* True

IF ((_answers < 100) AND (_dformat = "all"))    /* False

IF ((_answers < 100) OR (_dformat = "ide"))     /* True

IF ((_answers < 15) OR (_dformat = "ide"))      /* False

IF ((_answers < 100) XOR (_dformat = "bib"))    /* FALSE

IF ((_answers < 100) XOR (_dformat = "ide"))    /* True

Special Operators

\!

Edit

Edit a command before sending it to an online host (=> statement).

\>

L-number

Assign the L-number result of a command to a variable (=> statement).

#

answer count

Retrieve the number of answers from an L-number variable.

EXISTS

file existence

Determine whether a given file exists. EXISTS first checks the User Scripts folder and then Scripts folder. It sets _$filerror to zero if the file exists and to a nonzero value if the file does not exist.

Copyright © 2017 American Chemical Society. All Rights Reserved.