Timex Logic, Part 2

Authors

Publication

Date

Pages

BASIC Terms

In the preceding chapter we learned that logic is number oriented, and that conditions which are TRUE are replaced by the computer with a logic value of 1, and conditions which are FALSE are replaced by a logic value of 0. Program lines with statements containing a single logic condition usually present no problem to understand, either to devise when creating a program, or to determine their effect in one that is already existing.

But there are numerous occasions where two or more conditions must be acted upon jointly before the computer can take proper action. This is done by appropriately connecting the logic conditions with the logic operators, AND and OR.

AND can be likened to connecting two logic conditions in series, so that both conditions must be considered, one and then the other, before proper action can be taken. Such a statement might appear as…..

IF X>Y AND C=5 THEN....

In a diagram arrangement this same statement can be shown as….

In such a diagram we might consider computer functioning to be similar to the flow of current in an electrical circuit. The two conditions might then be analogous to switches in the circuit, closed if a condition is TRUE and open if it is FALSE. So visually, this diagram shows that AND requires both conditions to be TRUE for current to flow and the THEN action to take place.

OR, in a statement, can be likened to connecting two logic conditions in parallel so that if either condition is TRUE, its branch conducts and the THEN action takes place. Such a statement and its corresponding diagram might look like the following example……

IF X>Y OR C=5 THEN....

Statements may become more complex than these, but no matter how many logic conditions there may be, such a statement may always be diagramed by groupings of series and parallel circuits. The resulting diagram will be relatively easy to analyze. Where both AND and OR conditions occur in a statement, connect the AND conditions first as AND has a higher priority than OR. Consider the following statement……

IF X<4 OR X>8 AND Y>4 OR Y=2 AND Z<>0 THEN.....

This line would be diagramed by first connecting the AND conditions into series branches and then connecting the various branches in parallel. It would end up like……

From this diagram one can readily see that the THEN action will take place if any one of the three branches contains nothing but TRUE conditions, regardless of the status of the other two branches. For example, if X is equal to 3 (refer to the top branch), the THEN action occurs.

Parentheses, having a high priorty of 16, will affect the logic of a statement in which they appear. Priorty requires that the computer consider them first and the resulting diagram should show this. Insert some parentheses at random into the previous statement and it might look like……

IF (X=4 AND X>8) AND
(Y>4 OR Y=2 AND Z<>0) THEN..

Connecting the elements within the parentheses first, we get this diagram…..

Now it should be apparent at a glance that there are 4 paths by which current can flow; thus four possible combinations of conditions that will produce a THEN action.

In the use of diagrams, one can work backwards from a diagram to produce a statement of logic that will cover any conceivable set of conditions. It can be of considerable help to a programmer. It eliminates uncertainty and guess work, and perhaps the need for a lot of trial and error testing.

Although we used numerical conditions throughout these illustrations (because they need less space to show), conditions containing STRING$ are very common and can also be TRUE or FALSE. They would form diagrams in a similar manner. Later in this series we will encounter some.

This might be as good a place as any to inject a word of caution when using a condition such as Y=2 in the preceding statement. If the value of the variable Y is to be computed by the program, it may show up with a value of say 1.99999999, depending upon the factors used and the arithmetical operations which produce it. The computer does not consider such a value to be equivalent to 2, in a comparison. So you might want to write the condition as….. INT(Y+.1)=2, or what ever else might be needed to avoid a faulty comparison.

In the next chapter, we will explore other Boolean logic arrangements, and some others besides these that are uniquely Timex.

Products

 

Media

 

Image Gallery

Source Code

Scroll to Top