Relational Operators Operator Meaning < Less than > Greater than

Slides:



Advertisements
Similar presentations
If Statements & Relational Operators Programming.
Advertisements

Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
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.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
JavaScript, Fourth Edition
JavaScript, Third Edition
Chapter 4: Basic C Operators
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
Chapter 2 part #4 Operator
Decision Structures and Boolean Logic
Chapter 3: Data Types and Operators JavaScript - Introductory.
CHAPTER 2 PART #4 OPERATOR 2 nd semester King Saud University College of Applied studies and Community Service Csc 1101 By: Asma Alosaimi Edited.
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.
CPS120: Introduction to Computer Science Operations Lecture 9.
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 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.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Boolean Data Lesson CS1313 Fall Boolean Data Outline 1.Boolean Data Outline 2.Data Types 3.C Boolean Data Type: char or int 4.C Built-In Boolean.
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.
Principles of Programming Chapter 4: Basic C Operators  In this chapter, you will learn about:  Arithmetic operators  Unary operators  Binary operators.
By: Mr. Baha Hanene Chapter 6. LEARNING OUTCOMES This chapter will cover the learning outcome 02 i.e. 2.Use basic data-types and input / output in C programs.
Boolean values Gateway to decision making. Background Our problem-solving solutions so far have the straight-line property –They execute the same statements.
Chapter 4 Making Decision Csc 125 C++ programming language Fall 2005.
An Object-Oriented Approach to Programming Logic and Design Chapter 5 Making Decisions.
Operators.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
What are Operators? Some useful operators to get you started.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
Random Functions Selection Structure Comparison Operators Logical Operator
Rational Expressions relational operators logical operators order of precedence.
 Type Called bool  Bool has only two possible values: True and False.
Principles of Programming - NI July Chapter 4: Basic C Operators In this chapter, you will learn about: Assignment operators Arithmetic operators.
Relational Operator and Operations
Chapter 7: Expressions and Assignment Statements
Operators And Expressions
Rational Expressions. relational operators. logical operators
Sequence, Selection, Iteration The IF Statement
Bool operators and, or, not
CMPT 201 if-else statement
A mechanism for deciding whether an action should be taken
Relational Operations
Data Types, Identifiers, and Expressions
Chapter 7: Expressions and Assignment Statements
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.
Multiple variables can be created in one declaration
Topics The if Statement The if-else Statement Comparing Strings
Topics The if Statement The if-else Statement Comparing Strings
Logical Operators & Truth Tables.
And now for something completely different . . .
Computers & Programming Languages
Chapter 4: Control Structures I (Selection)
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.
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
Chapter 2: Java Fundamentals
Boolean Expressions to Make Comparisons
Herbert G. Mayer, PSU CS Status 7/19/2015
Relational and Logical Operators
Relational and Logical Operators
Chap 7. Advanced Control Statements in Java
Operator King Saud University
Relational and Logical Operators
5.03 Apply operators and Boolean expressions
Presentation transcript:

Relational Operators Operator Meaning < Less than > Greater than == Equal to <= Less than or equal to >= Greater than or equal to != Not equal to These are binary operators There must be expressions on either side of the operator Those expressions should evaluate to comparable types. The comparisons will evaluate to true (1) or false (0) Caution The two-character relational operators must appear exactly as written above, with the two characters in the proper order and without intervening spaces. Don’t confuse the assignment operator ( = ) with the relational operator ( == ).

Relational Expressions Numeric Expression Meaning Value 4 <= 5 4 less than or equal to 5 true(1) 4 != 4 4 not equal to 4 false(0) 4.0 == 4 real 4.0 equals integer 4 true(1) 4.0 >= 4.0 4.0 greater than or true(1) equal to 4.0 4.0 > 5.0 4.0 greater than 5.0 false(0)

Relational Expressions ASCII Characters Expression Meaning Value ‘B’ > ‘A’ ‘B’ greater than ‘A’ true(1) ‘g’ < ‘h’ ‘g’ less than ‘h’ true (1) ‘1’ < ‘2’ ‘1’ less than ‘2’ true(1) ‘B’ == ‘b’ ‘B’ equal to ‘b’ false(0) ‘B’ != ‘b’ ‘B’ not equal to ‘b’ true(1) ‘B’ > ‘a’ ‘B’ greater than ‘a’ false(0) ‘B’ > ‘1’ ‘B’ greater than ‘1’ true(1) ‘?’ > ‘!’ ‘?’ greater than ‘!’ true(1)

Logical Operators The three logical operators allow for creating more complex comparisons. Operator Meaning Type of operator ! Not unary && and binary || or binary

Logical Truth Tables p !p NOT truth tables true false false true Semantics of boolean expressions can be described by truth tables (where p and q represent boolean expressions) p !p NOT truth tables true false false true p q p && q AND truth table true true true true false false false true false false false false p q p || q _ OR truth table true false true false true true

Understanding Boolean Logic Suppose that char ans = ‘Y’; int sum = 23; int index = 17; double r = 7.5; int done = true; Evaluate (ans == ‘Y’) && (index != 0) ______ !(ans < ‘z’) ______ (sum == 45) || (index < r) ______ ( !done) && (index < 30) ______ done && (sum > 21) ______ (r <= r) || (!done) ______ (sum <= 40) || done && !(done) ______

Operator Precedence Operator Precedence Function calls highest ! + - & (Unary operators) * / % + - < <= >= > == != && || = lowest Note: You may use parentheses to change the order of evaluation.