| SCAN | Index Level | secondary |
| Syntax | |
| Category | BASIC |
| Type | Definition |
| Description |
brief discussion on how zero's, null's, strings and numbers are evaluated on various Pick platforms.
Traditionally, the result of a logical or Boolean expression is considered "true" if it evaluates to 1 and false if it evaluates to 0 (zero). In the Pick System, expressions which depend on a result of true or false also will evaluate other values as true or false. This tends to vary somewhat between implementations. In generic Pick, any non-zero integer that is positive or negative, evaluates to true. For example: x = 5 if x then stop Since x is a non-zero integer, the program takes the "then" branch and stops. In generic Pick, any zero or null value evaluates to false. For instance: y = "" if y then stop else print "yup" This prints "yup" since "y" is evaluated as false. Some Pick implementations additionally evaluate any negative numbers as false, and positive numbers as true. This also holds true for "+", "-", ".", "+." and "-.". This means that you will have to take the "truth test" with your system to determine how it handles true and false. This program will do it: loop print "value to test " : input value until value = "quit" do if value then print "true" else print "false" repeat Try it with negative numbers, null ( <return> ), positive numbers, letters and whatever else you can think of. A relational expression evaluates to 1 if the relation is true, and evaluates to 0 (zero) if the relation is false. Relational operators have lower precedence than all arithmetic and string operators. Therefore, relational operators are only evaluated after all arithmetic and string operations have been evaluated. In the logical expression: x=y The resolution of equal and unequal character pairs are handled as follows: - When both "x" and "y" are numeric, the comparison is numeric. - When either "x" is numeric and "y" is a string, or "x" is a string and "y" is numeric, the string is converted to an equivalent numeric, if possible. If the conversion is successful, the comparison is numeric. If the conversion is not possible, the number is converted to a string, and the comparison is lexical. - When both "x" and "y" are strings, both are converted to numeric, if possible, and the comparison is numeric. If the conversion is not possible, the comparison is lexical. The case of characters does not affect a comparison if "casing" is off. For example: if "a" = "A" then.. This is true with "casing off". It is false with "casing on". |
| Options | |
| See Also | FOR ... NEXT logical expressions NOT > THEN logical expressions PRECISION precedence IF NUM ALPHA null, evaluation ELSE zero, evaluation LOOP = IFR |
| Example |
x = "1"
y = "001" if x=y then crt 'equal' else crt 'not equal' "equal" is displayed, as both "x" and "y" evaluate to a numeric "1". |
| Warnings | "casing on or off" can change the results of alphanumeric comparisions. |
| Compatibility | D3 7.0 AP R83 |
| SCAN | Index Level | secondary |