Download presentation
Presentation is loading. Please wait.
Published byBlaze Barnard Simpson Modified over 9 years ago
2
Selection Boolean
3
What is Boolean ? Boolean is a set with only two values : –true –false true and false are standard identifiers in Pascal, called Boolean constants
4
Boolean Expression Boolean expressions are always in the form of – expression-1 and expression2 could be any valid expressions The value of a Boolean expression is either true or false
5
Relational Operator Meaning = <> > >= < <= equal to not equal to greater than greater than or equal to less than less that or equal to
6
Rules on Boolean Expression On each side of the relational operator, there must be one and only one expression (operand) Relational operator have lowest order of precedence, therefore all the calculation of both operands are performed before the relational operation Both operands must be of the same type
7
Rules on Boolean Expression When comparing two character/string, the ASCII values of the operands are compared. The comparison of character/string starts from the first character of both operands. If the first characters are the same, the second characters are compared, until there is different.
8
Examples Boolean expressionValue 3 > 4 ‘a’ <= ‘b’ 3 * 4 < 5 * 2 ‘abcd’ > ‘abcde’ 10.0 = 10 ‘123’ > ‘5’ ‘A’ > ‘z’ false true false true false
9
Boolean Data Type Boolean is one of the data types in Pascal (like integer, real, string ……) A Boolean variable contains one of the two possible values: true or false Example: –var bool1, bool2 : boolean; –bool1 := 1 > 3; –bool2 := false;
10
Boolean Operators Operate on Boolean expressions Perform logical operations Three Boolean operators: –not –and –or
11
and Operator Value is true only if both operands are true Otherwise, the value is false pqp and q true false true false true false true false Truth Table
12
or Operator Value is true if any one of the two operands is true Value is false only when both operands are false pqp or q true false true false true false true false
13
not Operator not is an unary operator (operator with only one operand) Value is the negation of the operand pnot p true false true
14
Order of Precedence OperatorPriorityCategory not - (unary minus)highestUnary Operators * / div mod andMultiplying Operators + - orAdding Operators = <> > >= < <=lowestRelational Operators
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.