basic.logical.expressions

Definition/BASIC Program, Releases: AP and R83

application of logical (Boolean) operators to relational or arithmetic expressions.

Description

application of logical (Boolean) operators to relational or arithmetic expressions. The result of an operation has two states; 'true' and 'false'. Logical expressions are considered false when equal to zero, and are considered true when non-zero.

Logical operators have the lowest precedence and are evaluated after all other operations have been evaluated. If two or more logical operators appear in an expression, the leftmost is performed first.

Logical operators act on their associated operands as follows:

a OR b is true (evaluates to 1) if a is true or b is true.

a ! b is false (evaluates to 0) if a and b are both false.

a AND b is true (evaluates to 1) only if both a and b are true.

a & b is false (evaluates to 0) if a is false or b is false or both are false.

The 'not' function negates the effect of a logical expression:

not(a or b) is true (evaluates to 1) if a is false or b is false.

not(a and b) is true (evaluates to 1) if a and b are false.

Example

if x then...

The 'then' clause is taken when 'x' is a non-zero numeric.
Whether x is a numeric constant, or an ASCII string, any non-zero numeric value
of 'x' is true.

word = 'apple'
chr = word[1,1]
print 'A':
print str('n',chr='a' or chr = 'e' or chr =
'i' or chr = 'o' or chr = 'u') :
print ' ':word

This prints 'An apple', because chr = 'a'.

visit.date = customer.item<5>
if visit.date then ...

In this example, the 'then' clause is executed if
'visit.date' evaluates to a non-zero numeric.

if x > 1 and x < 10 then...

The 'then' clause is taken if 'x' is between 1 and 10,
exclusive.

if (x > 1 and x < 10) or (x >= 100 and x <= 200) then...

The 'then' clause is taken if either 'x' is between 1 and
10, exclusive, or between 100 and 200, inclusive.

if not(print.flag = 'n') then printer on

The 'printer on' statement is executed if the value of
'print.flag' is not 'n'.

See Also

Command Name Type Description
data.representation Definition two types of data: numeric and string.
expression Definition Description of expression.
basic.relational.operators Relational Operator Returns the relationship between two expressions.
basic.case Statement Initiates the case statement.
string.expressions Definition A string of characters.
basic.precedence Definition Precedence of compound expressions.
basic.null Statement No-op compiler directive.
basic.else Statement In-line initiator.
basic.arithmetic.expressions Definition Arithmetic expressions.
basic.if Statement Initiates logical expression.
basic.search.for.truth Definition Evaluation of null and zero.
basic.and Logical Operator Boolean operator.
basic.! Logical Operator Logical 'or' operator and remark line indicator.
basic.ifr Statement Initiates a multi-attribute logical expression.

User Comments

What do you think?

Share your experience or ask a question by using the form below.

Login to leave your comments.