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.
|
String Operators |
|
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
Numbers
Strings
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.
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 |
|
Copyright
© 2017 American Chemical Society. All Rights Reserved.