B065: PROGRAMMING OPERATORS AND SELECTION 2. Starter  What do each of the following mean? Write an example of how each could be used. Symbol = < <= >

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Chapter 4 - Control Statements
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.
1 CSC103: Introduction to Computer and Programming Lecture No 8.
Conditional Statements If these were easy then everyone would them!
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
2-1 Making Decisions Sample assignment statements PayAmount = Hours * Rate PayAmount = 40*Rate + (Hours – 40)*Rate*1.5.
Flow control 1: if-statements (Liang 72-80) if(radius < 0) { System.out.println(“cannot get area: radius below zero”); } else { double area = radius *
Chapter 4: Control Structures: Selection
Administrative MUST GO TO CORRECT LAB SECTION! Homework due 11:59pm on Tuesday. 25 points off if late (up to 24 hours) Cannot submit after 11:59pm on Wednesday.
Do it now activity Correct the 8 syntax errors: Age = input(“How old are you?” If age = 10 Print(You are 10”) else: print(“You are not 10”)
Programming Logic and System Analysis
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Decisions – Chapter 3 IPC144 Week 2. IPC144 Introduction to Programming Using C Week 2 – Lesson 2 (Pages 12 to 18 in IPC144 Textbook)
Agenda Control Flow Statements Purpose test statement if / elif / else Statements for loops while vs. until statements case statement break vs. continue.
EGR 2261 Unit 4 Control Structures I: Selection  Read Malik, Chapter 4.  Homework #4 and Lab #4 due next week.  Quiz next week.
Programming Logic and Design Fourth Edition, Introductory
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.
1 2.2 Selection Logical Operators. 2 Learning Objectives Explain how the logical operator AND Boolean statements works.
Problem Solving with Decisions
Monday, Jan 13, 2003Kate Gregory with material from Deitel and Deitel Week 2 Questions from Last Week Control Structures Functions Lab 1.
Conditionals & boolean operators
Agenda Exam #1 Review Modulus Conditionals Boolean Algebra Reading: Chapter Homework #5.
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.
1 Boolean Expressions to Make Comparisons Boolean expression –Represents only one of two states –Expression evaluates to either true or false Expressions.
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.
Selection Relational Expressions A condition or logical expression is an expression that can only take the values true or false. A.
PROGRAM FLOW CHAPTER3 PART1. Objectives By the end of this section you should be able to: Differentiate between sequence, selection, and repetition structure.
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.
IT CS 200: C ONDITION Lect. Napat Amphaiphan. T HE ABILITY TO CONTROL THE FLOW OF YOUR PROGRAM, LETTING IT MAKE DECISIONS ON WHAT CODE TO EXECUTE 2.
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.
Chapter 3 Decisions Three control structures Algorithms Pseudocode Flowcharts If…then …else Nested if statements Code blocks { } multi statement blocks.
CPS120: Introduction to Computer Science Decision Making in Programs.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 5 Making Decisions.
BO65: PROGRAMMING ITERATION 1. Starter  Write down what you think the code below outputs on screen: Dim intCounter as integer intCounter = 0 Do while.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
B065: PROGRAMMING Variables 2. Starter  What is wrong with the following piece of code: Option Explicit Off Dim num1 as string Dim num2 as integer num1.
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.
A First Book of C++ Chapter 4 Selection.
More on the Selection Structure
Chapter 4: Making Decisions.
Microsoft Visual Basic 2005 BASICS
More Selections BIS1523 – Lecture 9.
Topics The if Statement The if-else Statement Comparing Strings
2-1 Making Decisions Sample assignment statements
Computers & Programming Languages
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Control Structures: Selection Statement
IPC144 Introduction to Programming Using C Week 3 – Lesson 1
Visual Basic – Decision Statements
Chapter 5: Control Structure
PYTHON: BUILDING BLOCKS Sequencing & Selection
Boolean Expressions to Make Comparisons
Relational Operators.
Programming In Lesson 4.
Control Structures: Selection Statement
OPERATORS AND SELECTION 2
Chapter 5: The Selection Structure
A3 2.1d To Solve Compound Inequalities
Presentation transcript:

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 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 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 in Chapter 4 of your handbook. Complete all for homework.

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

Required Reading Each week you will be given required reading. If you fail to do this, you will 100% find the lessons which follow it EXTREMELY difficult. Before next lesson you should have read: Pre-reading – Chapter 5

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.