OPERATORS AND SELECTION 2

Slides:



Advertisements
Similar presentations
Chapter 4 - Control Statements
Advertisements

1 Conditional Statement. 2 Conditional Statements Allow different sets of instructions to be executed depending on truth or falsity of a logical condition.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Topic: Compound Areas Learning objectives: Calculate the area of shapes made from rectangles Identify the necessary information to simplify a problem.
2-1 Making Decisions Sample assignment statements PayAmount = Hours * Rate PayAmount = 40*Rate + (Hours – 40)*Rate*1.5.
true (any other value but zero) false (zero) expression Statement 2
Flow control 1: if-statements (Liang 72-80) if(radius < 0) { System.out.println(“cannot get area: radius below zero”); } else { double area = radius *
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Chapter 4: Control Structures: Selection
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
Programming Logic and System Analysis
B065: PROGRAMMING OPERATORS AND SELECTION 1. Starter  Have a go at the All Logic Signs activity.  COMP1  Programming  8 Selection  All Logic Signs.xls.
Object-Oriented Programming Using C++ Third Edition Chapter 3 Making Decisions.
CPS120: Introduction to Computer Science Decision Making in Programs.
B065: PROGRAMMING OPERATORS AND SELECTION 2. Starter  What do each of the following mean? Write an example of how each could be used. Symbol = <
Conditionals & boolean operators
Logic Disjunction A disjunction is a compound statement formed by combining two simple sentences using the word “OR”. A disjunction is true when at.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Compound Inequalities A compound inequality is a sentence with two inequality statements joined either by the word “or” or by the word “and.” “And”
CPS120: Introduction to Computer Science Decision Making in Programs.
CHAPTER 4: Selection Control Structure. Objectives  Use the relational comparison operators  Learn about AND logic  Learn about OR logic  Make selections.
Conditional Statement Chapter 8. Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement.
© The McGraw-Hill Companies, 2006 Chapter 2 Selection.
BACS 287 Programming Logic 2. BACS 287 Sequence Construct The sequence construct is the default execution mode for the CPU. The instructions are executed.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Chapter 4 October 22, The If Statement Programs make decisions If(condition){ Statement(s); } Condition  boolean expression Evaluates to either.
CPS120: Introduction to Computer Science Decision Making in Programs.
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
PHY 107 – Programming For Science. Today’s Goal  How to use while & do / while loops in code  Know & explain when use of either loop preferable  Understand.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Chapter 4: Control Structures I
CNG 140 C Programming (Lecture set 3)
More on the Selection Structure
AND.
Chapter 4: Control Structures I
Sequence, Selection, Iteration The IF Statement
Chapter 4: Making Decisions.
Chapter 3: Introduction to Logic
The Selection Structure
Topics The if Statement The if-else Statement Comparing Strings
Javascript Conditionals.
Agenda Control Flow Statements Purpose test statement
Microsoft Visual Basic 2005 BASICS
Chapter 4: Control Structures I
More Selections BIS1523 – Lecture 9.
Topics The if Statement The if-else Statement Comparing Strings
ICS 3U Tuesday, September 21st.
2-1 Making Decisions Sample assignment statements
Computers & Programming Languages
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Selection Statements Chapter 4 Attaway MATLAB 4E.
Control Structures: Selection Statement
Introduction to Computer Programming
Flow Control Statements
Visual Basic – Decision Statements
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
PYTHON: BUILDING BLOCKS Sequencing & Selection
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Relational Operators.
Programming In Lesson 4.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Chapter 3: Selection Structures: Making Decisions
Control Structures: Selection Statement
Chapter 5: The Selection Structure
Chapter 3: Selection Structures: Making Decisions
Selection Statements Chapter 4 Attaway MATLAB 5E.
Presentation transcript:

OPERATORS AND SELECTION 2 B065: PROGRAMMING OPERATORS AND SELECTION 2

Starter What do each of the following mean? Write an example of how each could be used. Symbol = < <= > >= <> AND OR NOT

Objectives Understand what is meant by selection in programming. Explore selection programming commands: IF, SELECT CASE Understand the use of logical operators.

Logical Operator: AND Sometimes, we may have more than one condition involved in a decision. If (age > 65) And (theDay = "Thursday") Then cost = 0.9 * cost End If Other Examples: (7 < 10) And (7 > 4) is True (6 <> 5) And (6 < 3) is False

Logical Operator: OR Sometimes we are happy to accept either of two conditions as the basis for carrying out some action. We might want to issue an error message if a mark is entered as either less than 0 or greater than 100, for example. The logical Or operator is provided to deal with this situation. If (mark < 0) Or (mark > 100)Then Console.WriteLine("Error in data") End If

Combining Logical Operators It is possible to form quite complicated expressions by combining conditions with several logical operators. For example, ((status = "Temp") And (hours < 30)) Or (status = "Part-time") will be True in two cases status has the value "Temp" and hours has a value less than 30 status has the value "Part-time“ In such compound conditions, the bracketing is vitally important.

Simplifying Selection with CASE Nested IF statements can become somewhat confusing and hard to write and later interpret. Sometimes a CASE statement can be used, which is a list of options to compare something to. If there is a match, then some statements can then be executed.

A Worked Example of CASE

Tasks Complete questions 6-12 in Chapter 4 of your handbook.

Objectives Review Understand what is meant by selection in programming. Explore selection programming commands: IF, SELECT CASE Understand the use of logical operators.

Plenary We will now go through each of the solutions for the tasks set. Each person will show their code as an example and explain what it does.