1 / 13

Selection

Selection. Boolean. What is Boolean ?. Boolean is a set with only two values : true false true and false are standard identifiers in Pascal, called Boolean constants. Boolean Expression. Boolean expressions are always in the form of

lamont
Download Presentation

Selection

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Selection Boolean

  2. What is Boolean ? • Boolean is a set with only two values : • true • false • true and false are standard identifiers in Pascal, called Boolean constants

  3. Boolean Expression • Boolean expressions are always in the form of • <expression-1> <relational operator> <expression-2> • expression-1 and expression2 could be any valid expressions • The value of a Boolean expression is either true or false

  4. Relational Operator

  5. 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

  6. 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.

  7. Examples false true false false true false false

  8. 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;

  9. Boolean Operators • Operate on Boolean expressions • Perform logical operations • Three Boolean operators: • not • and • or

  10. Truth Table and Operator • Value is true only if both operands are true • Otherwise, the value is false

  11. or Operator • Value is true if any one of the two operands is true • Value is false only when both operands are false

  12. not Operator • not is an unary operator (operator with only one operand) • Value is the negation of the operand

  13. Order of Precedence

More Related