1 / 12

Boolean Operators and Pascal Sets in Programming

Learn about boolean operators like AND, OR, and NOT, and how to use sets in Pascal programming. This section includes examples and explanations.

slarrick
Télécharger la présentation

Boolean Operators and Pascal Sets in Programming

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. We will not cover the following sections in class: • 7.2 • 7.4 • 7.8 (we will discuss the design topics) • You ARE responsible for knowing the topics covered in these sections. • The topics are covered in the other sections of the chapter. However, these sections contain very good examples and you should study them.

  2. Boolean Operators: AND If (BoolEx1) AND (BoolEx2) THEN writeln(‘Both expressions are true’); When using the AND Operator, both expressions must be TRUE for the compound expression to be true.

  3. Boolean Operators: OR If (BoolEx1) OR (BoolEx2) THEN writeln(‘At least one expression is true’); When using the OR Operator, at least one expression must be TRUE for the compound expression to be true.

  4. Boolean Operators: NOT If NOT (BoolEx) THEN writeln(‘BoolEx is FALSE’); The NOT Operator simply reverses the boolean value of the boolean expression that appears immediately to its right. NOT (a <= 2) OR (b = 2) will evaluate to TRUE if a is greater than 2 and / or b =2.

  5. Pascal Sets • In Pascal you can define sets by placing a group of ‘elements’ of any single ordinal type between brackets. • [‘A’, ‘E’, ‘I’, ‘O’, ‘U’] • [1..9] {all values between 1 and 9}

  6. Pascal Sets: The IN operator • The boolean operator IN is used to test whether an item is an element of a set. FOR Letter := ‘A’ TO ‘Z’ DO IF Letter IN [‘A’, ‘E’, ‘I’, ‘O’, ‘U’] THEN write(letter);

  7. Precedence Priority Operator(s) 1st NOT 2nd AND, *, /, DIV, MOD 3rd OR, +, - 4th =, <>, >, <, >=, <=, IN

  8. Section 7.7 Skip for now we may revisit include files

  9. Sections 7.8 Per first slide, we will discuss the design issues in another class. You should read and “grok” this section’s example

  10. Nested IF Statements When you nest IF statements, an else will match to the closest ‘non-matched’ IF. IF Age >= 21 THEN IF Age <= 35 THEN writeln(‘come in’) ELSE writeln(‘Do you know this is a college bar’); The ELSE will match with IF AGE <= 35

  11. Multiple Alternative IF-THEN-ELSE • The multiple IF-THEN-ELSE is a multiway switch that allows you to choose only one of many options. IF A < 10 THEN … ELSE IF A < 15 THEN … ELSE ...

  12. Homework #6 • Due next Thursday, November 11 • On Marateck’s website homework #5 • The assignment is like a “version 2.0” of the one due today.

More Related