**basic.search.for.truth**Definition/BASIC Program

# basic.search.for.truth

Command | basic.search.for.truth Definition/BASIC ProgramApplicable release versions: AP, R83 |
---|---|

Category | BASIC Program (486) |

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". |

Syntax | |

Options | |

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". |

Purpose | |

Related |
basic.for.next basic.logical.expressions basic.not basic.> basic.then basic.logical.expressions basic.precision basic.precedence basic.if basic.num basic.alpha basic.null.evaluation basic.else basic.zero.evaluation basic.loop basic.= basic.ifr |