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.

Slides:



Advertisements
Similar presentations
If Statements & Relational Operators Programming.
Advertisements

Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control if-else and switch statements.
10 November JavaScript. Presentation Hints What do YOU think makes a good presentation Some of my suggestions Don’t write full sentences on slides Talk,
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
CS 117 Spring 2002 Decision Making Hanly Chapter 3 Friedman-Koffman Chapter 4.
JavaScript, Fourth Edition
Boolean Logic & Truth Tables In today’s lesson we will look at: a reminder about truth values and NOT, AND, OR and EOR truth tables operator precedence.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Problem Solving for Programming Session 7 Data Types for Computer Programs.
CSci 125 Lecture 10 Martin van Bommel. Simple Statements Expression followed by semicolon Assignments total = n1 + n2; Function calls printf(”Hello.\n”);
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
Decision Structures and Boolean Logic
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Dale Roberts Program Control using Java - Boolean Expressions Dale Roberts, Lecturer Computer Science, IUPUI Department of.
1 Conditional statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
© 2006 Pearson Education 1 Obj: to use compound Boolean statements HW: p.184 True/False #1 – 6 (skip 3)  Do Now: 1.Test your “Charge Account Statement”
1 Week 2: Variables and Assignment Statements READING: 1.4 – 1.6 EECS Introduction to Computing for the Physical Sciences.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 6, Lecture 1 (Monday)
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Lesson - 7. Operators There are three types of operators: Arithmetic Operators Relational and Equality Operators Logical Operators.
Decisions  Relational operators  Operate on two numbers or two Strings  ==, !=, >, >=,
Computer Science 1620 boolean. Types so far: Integer char, short, int, long Floating Point float, double, long double String sequence of chars.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
1 Compound Assignment C++ has a large set of operators for applying an operation to an object and then storing the result back into the object Examples.
1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA.
Boolean Logic Logical Operators Comparison Operators Truth tables.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
1 st semester Basic Pascal Elements อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
1 Chapter 4, Part 1 If Control Construct A mechanism for deciding whether an action should be taken JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S.
Chapter 51 Decisions Relational and Logical Operators If Blocks Select Case Blocks.
Flow of Control Unless indicated otherwise, the order of statement execution through a method is linear: one after the other in the order they are written.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Repetition. Loops Allows the same set of instructions to be used over and over again Starts with the keyword loop and ends with end loop. This will create.
Conditions, Logical Expressions, and Selection Control Structures ROBERT REAVES.
Relational and Boolean Operators CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Boolean values Gateway to decision making. Background Our problem-solving solutions so far have the straight-line property –They execute the same statements.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
ICS102 Lecture 8 : Boolean Expressions King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 15, 2004 Lecture Number: 11.
Random Functions Selection Structure Comparison Operators Logical Operator
Rational Expressions relational operators logical operators order of precedence.
1 DAI-C5-UD 1 Main Objects in Programming Languages Academic Year DAI. Credit 5 (Structured and modular programming) Ferran Chic (Ref: TR )
 Type Called bool  Bool has only two possible values: True and False.
Rational Expressions. relational operators. logical operators
Brent M. Dingle Texas A&M University Chapter 6, Sections 1 and 2
A mechanism for deciding whether an action should be taken
Data Types, Identifiers, and Expressions
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Topics The if Statement The if-else Statement Comparing Strings
Assignment statement and Arithmetic operation 2
Expressions and Control Flow in JavaScript
JavaScript conditional
Topics The if Statement The if-else Statement Comparing Strings
Logical Operators & Truth Tables.
Computers & Programming Languages
Relational Operators Operator Meaning < Less than > Greater than
Summary Two basic concepts: variables and assignments Basic types:
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Expressions.
Life is Full of Alternatives
OPERATORS AND EXPRESSIONS IN C++
Chap 7. Advanced Control Statements in Java
boolean Expressions Relational, Equality, and Logical Operators
Conditionals.
Presentation transcript:

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 – expression-1 and expression2 could be any valid expressions The value of a Boolean expression is either true or false

Relational Operator Meaning = <> > >= < <= equal to not equal to greater than greater than or equal to less than less that or equal to

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

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.

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

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;

Boolean Operators Operate on Boolean expressions Perform logical operations Three Boolean operators: –not –and –or

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

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

not Operator not is an unary operator (operator with only one operand) Value is the negation of the operand pnot p true false true

Order of Precedence OperatorPriorityCategory not - (unary minus)highestUnary Operators * / div mod andMultiplying Operators + - orAdding Operators = <> > >= < <=lowestRelational Operators