![]() |
IFName:
The following logical operators are used to compare two parameters
The following can be used to test for the existence (or non-existence) of a parameter
In addition, you can use AND, OR, and XOR to combine testing for two or more (up to 10) conditions. With AND, the result is true if both conditions are true and false otherwise. With OR, the result is true if either, or both, conditions are true and false if both conditions are false. With XOR, the result is true if either, but not both, of the conditions are true and false otherwise. Note that the AND, OR, and XOR clause are evaluated pairwise left to right. Currently, the use of parenthesis to group clauses is not supported. For example,
is evaluated as follows
The following syntax is not supported
This would need to be coded as
The NOT clause can be used to negate the result. That is, if the condition is true, the NOT will result in a false condition. Likewise, if the condition is false, the NOT will result in a true condition.
where <par1> is a number or parameter; <log> is a logical operator (=, <>, <, >, <=, >=) that defines the comparison between the two parameters; and <par2> is a number or parameter. That is, this syntax is used to compare two parameters (or numbers) and determine whether the expression is true or false. Strings can be used with the "=" and "<>" operators, but not the others. This is most basic and most common use of the IF command.
where <par1> is a number or parameter; <log> is a logical operator (=, <>, <, >, <=, >=) that defines the comparison between the two parameters; and <par2> is a number or parameter. This is similar to Syntax 1. The distinction is that it reverses the result. That is, if the <par1> <log> <par2> condition is evaluated as true, the final result is false. Likewise, if the <par1> <log> <par2> condition is evaluated as false, the final result is true. Strings can be used with the "=" and "<>" operators, but not the others.
where <name> is the name being tested. This syntax is used to determine whether <name> exists in the Dataplot name table. It returns true if <name> is found in the name table and false if it is not.
where <name> is the name being tested. This syntax is used to determine whether <name> exists in the Dataplot name table. It returns true if <name> is not found in the name table and false if it is found in the name table.
where <par1> is a number or parameter; <log1> is a logical operator (=, <>, <, >, <=, >=) that defines the comparison between the two parameters; <par2> is a number or parameter; <par3> is a number or parameter; <log2> is a logical operator (=, <>, <, >, <=, >=) that defines the comparison between the two parameters; and <par4> is a number or parameter. The two conditions <par1> <log1> <par2> and <par3> <log2> <par4> are evaluated separately. The two results are then combined based on the AND, OR, or XOR clause. If the AND clause is used, then the final result is true if both conditions are true and false otherwise. If the OR clause is used, then the final result is true if either condition, or both, are true and false otherwise. If the XOR clause is used, then the final result is true if one of the conditions is true and the other is false. If both conditions are true or both conditions are false, the final result is false. Strings can be used with the "=" and "<>" operators, but not the others. The AND, OR, and XOR can also be used with Syntax 2, Syntax 3, and Syntax 4. The capability to have more than one AND, OR or XOR clause was added for the 2018/02 version. Up to 10 clauses may be entered.
where <name> is the name being tested. Dataplot supports named arguments with the CALL command (see HELP MACRO SUBSTITUTION CHARACTER for details). This syntax is used to determine whether <name> is a currently defined argument on the CALL command. If <name> exists, the IF status is set to true. Otherwise it is set to false.
where <name> is the name being tested. Dataplot supports named arguments with the CALL command (see HELP MACRO SUBSTITUTION CHARACTER for details). This syntax is used to determine whether <name> is a currently defined argument on the CALL command. If <name> does not exist, the IF status is set to true. Otherwise it is set to false.
where <expr> is an arithmetic expression; <par2> is a number or parameter; <log> is a logical operator (=, <>, <, >, <=, >=) that defines the comparison between the two parameters; <par3> is a number or parameter; and where <par1> is a parameter where the result of <expr> is stored. This syntax allows conditional execution of an arithmetic expression. For example,
Note that this is limited to arithmetic expressions, so commands like the following are not supported
LET Y2 = CODE Y IF IFLAG = 1
IF A > 2 IF A < 2 IF A <> 2 IF A NOT EXIST IF A >= 2 IF A <= 2
IF A > 2 AND B < 5
LET A = B IF B > 0
is equivalent to
Although this syntax is allowed, it is recommended that the "=" be included.
This was implemented 7/1999. Previous versions left the status undefined.
LET STRING S = TEST IF S = TEST PRINT S END OF IF LET STRING S = TEST IF S <> "NOT TEST" PRINT S ENDS OF IF Note that "=" and "<'>" are the only comparisons allowed (i.e., no "<" or ">"). Note: The 2018/10 version added the following
IF S1 <= S2 IF S1 > S2 IF S1 >= S2 where S1 and S2 are pre-defined strings. The comparison is based on the ASCII coding sequence (so "A" is less than "a" and "C" is less than "b"). The comparison is performed left to right. If one string is shorter than the other, the shorter string will return 0 for the ASCII code when its length has been exceeded. This syntax does not currently work with literal strings. The argument on the left of the "=" must be the name of a previously defined string. The argument to the right of the "=" is a literal string. The string can be enclosed in dooble quotes if it contains spaces. If there are no double quotes, the string is assumed to end once the first space is encountered. The 2014/11 version modified this so that the right hand side can now be the name of a previously defined string as well as a literal string. The 2018/05 version modified this so that the left hand side can supported literal strings. Note that literal strings on the left hand side must be enclosed in quotes. For example, the following are now all supported (S and T are assumed to be pre-defined strings)
IF "xxxx" = T IF S = "xxxx" IF "xxxx" = "xxxx" However, be aware that the following may not be interpeted as expected
This is not doing a string comparison. It is checking to see if U is the name of a parameter or string. If U does not exist, the IF status is set to false. If U does exist as a parameter or string, the IF status will be set to true. So effectively, this is equilavent to
Also, when testing strings, a string containing a single blank character is considered equal to a string with zero characters. That is,
will evaluate to true. Note:
IF 3 > A That is, the left hand side can now be a number as well as a parameter (previous versions already supported numbers on the right hand side). An example of where this can be useful is
The $0 returns the number of command line arguments for a macro. The $0 is evaluated before the IF command is processed, so the IF command would in fact see something like
2002/07: Support for testing strings 2014/11: When comparing strings, allow right hand side to be a previously defined string 2016/10: Support for IF COMMAND LINE ARGUMENT ... EXISTS 2016/10: Support for NOT 2016/10: Support for AND, OR, and XOR 2018/02: AND, OR, and XOR extended to up to 10 clauses 2018/02: For IF A = ..., when A does not exist set IF status to false but do not treat as an error 2018/05: Support numeric value for left hand side (e.g., IF A > 2) 2018/05: Support quoted literal string for left hand side (e.g., IF "xxxx" = xxxxx) 2018/05: Support for IF COMMAND LINE ARGUMENT ... NOT EXIST 2018/05: Better feedback for special cases 2018/10: "<", "<=", ">", ">=" support for strings LET Y1 = NORMAL RANDOM NUMBERS FOR I = 1 1 100 LET A = Y1(10) IF A < 0 LET Y1(10)=ABS(A) END OF IFProgram 2: let a = 3 let b = 5 . if a = 3 and b = 5 print "AND Syntax Both True: True" else print "AND Syntax Both True: False" end of if pause . if a = 3 and b = 2 print "AND Syntax A True, B False: True" else print "AND Syntax A True, B False: False" end of if pause . if a = 3 or b = 5 print "OR Syntax Both True: True" else print "OR Syntax Both True: False" end of if pause . if a = 3 or b = 2 print "OR Syntax A True, B False: True" else print "OR Syntax A True, B False: False" end of if pause . if a = 1 or b = 5 print "OR Syntax A False, B True: True" else print "OR Syntax A False, B True: False" end of if pause . if a = 1 or b = 2 print "OR Syntax A False, B False: True" else print "OR Syntax A False, B False: False" end of if pause . if a = 3 xor b = 5 print "XOR Syntax Both True: True" else print "XOR Syntax Both True: False" end of if pause . if a = 3 xor b = 2 print "XOR Syntax A True, B False: True" else print "XOR Syntax A True, B False: False" end of if pause . if a = 1 xor b = 5 print "XOR Syntax A False, B True: True" else print "XOR Syntax A False, B True: False" end of if pause . if a = 1 xor b = 2 print "XOR Syntax A False, B False: True" else print "XOR Syntax A False, B False: False" end of if
|
Privacy
Policy/Security Notice
NIST is an agency of the U.S.
Commerce Department.
Date created: 01/27/2017 |