13.07.2015 Views

Turbo Basic

Turbo Basic

Turbo Basic

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Relational OperatorsRelational operators allow you to compare the values of two strings or two numbers(but not one of each) to obtain a Boolean result of TRUE or FALSE. The result ofthe comparison is assigned an integer value of - 1 if the relation is TRUE, and 0 ifthe relation is FALSE. For example:PRINT 5 > 6, 5 < 6, (5 < 6) * 15prints out 0, - 1, and - 15. Although they can be used in any numeric expression(for example, a = (b > c) / 13), the numeric results returned by relational operatorsare generally used in an IF or other decision statement to make a judgmentregarding program flow. Table 4-3 lists the relational operators.Table 4-3Relational OperatorsOperator Relation ExampleEqualityx = y Inequality xy< Less than x < y> Greater than x > y=yWhen arithmetic and relational operators are combined in an expression, arithmeticoperations are always evaluated first. For example, 4 + 5 < 4 * 3 evaluatesto -1 (TRUE), because the arithmetic operations are carried out before the relationaloperation, which ultimately tests the truth of the assertion: 9 < 12.Logical OperatorsLogical operators perform logical (Boolean) operations on integers. Used with relationaloperators, they allow you to set up complex tests likeIF day> 29 AND month = 2 THEN PRINT "Error in date"This statement performs a logical AND on the integer results returned by thetwo relational operators. (The AND operator has a lower priority than the " > " and"=" relational operators, so parentheses aren't needed.) For example, if day = 30and month = 2, both relational operators return TRUE (- 1). The underlyingbinary representation of integers is such that - 1 has a value of &HFFFF (all bitsturned on); 0 is &HOOOO, all bits turned off.The AND operator then performs a logical AND on these two TRUE results:1111 1111 1111 1111 (-1)AND 1111 1111 1111 1111 (-1)1111 1111 1111 1111 (-1)producing a TRUE (nonzero) result.<strong>Turbo</strong> <strong>Basic</strong>: The Language 79

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!