Vtech PreComputer Power Pad Plus User Manual - Page 63

Logical Operators

Page 63 highlights

Example: 40 IF P=6 THEN PRINT "TRUE" ELSE PRINT "FALSE" In this example, if P=6 the computer will print TRUE. Any other value will print FALSE. In either case the computer will carry onto the next line. It is possible for more than one statement to follow the THEN or ELSE command. A colon separates the statements. Example: 50 IF A =5 THEN PRINT "TRUE": S=S-3: GOTO 90 ELSE PRINT "FALSE": K=K+8 So if A equals 5 the computer will print TRUE, subtract 3 from the variable S and go to line 90. If A does not equal 5 the computer will print FALSE, add 8 to the variable K and then carry on with the next normal line. LOGICAL OPERATORS Logical operators are used IF...THEN...ELSE and such statements where a condition is used to determine subsequent operations within the user program. The logical operators are: AND, OR, and NOT. For the purpose of this discussion, A and B are relational expressions having only TRUE and FALSE. Logical operations are performed after mathematical and relational operations. Operator NOT AND Example NOT A A AND B OR A OR B Meaning If A is true, NOT A is false. A AND B has the value true, only if A and B are both true. A AND B has the value false if either A or B is false. A OR B has the value true if either A or B or both are true. It has the value false if both are false. 59

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88

59
Example:
40
IF P=6 THEN PRINT “TRUE” ELSE PRINT “FALSE”
In this example, if P=6 the computer will print
TRUE
. Any other value will print
FALSE
.
In either case the computer will carry onto the next line.
It is possible for more than one statement to follow the
THEN
or
ELSE
command.
A colon
separates the statements.
Example:
50
IF A =5 THEN PRINT “TRUE”: S=S-3:
GOTO 90 ELSE PRINT “FALSE”: K=K+8
So if A equals 5 the computer will print
TRUE
, subtract 3 from the variable S and go to
line 90.
If A does not equal 5 the computer will print
FALSE
, add 8 to the variable K
and then carry on with the next normal line.
LOGICAL OPERATORS
Logical operators are used
IF
...
THEN
...
ELSE
and such statements where a condition is used
to determine subsequent operations within the user program.
The logical operators are:
AND
,
OR
, and
NOT
.
For the purpose of this discussion, A and B are relational expressions having only
TRUE
and
FALSE
. Logical operations are performed after mathematical and relational operations.
Operator
Example
Meaning
NOT
NOT A
If A is true, NOT A is false.
AND
A AND B
A AND B has the value true, only if A and B
are both true.
A AND B has the value false if either A or B
is false.
OR
A OR B
A OR B has the value true if either A or B or
both are true.
It has the value false if both are false.