B065: PROGRAMMING OPERATORS AND SELECTION 1. Starter  Have a go at the All Logic Signs activity.  COMP1  Programming  8 Selection  All Logic Signs.xls.

Slides:



Advertisements
Similar presentations
5.04 Apply Decision Making Structures
Advertisements

1 Week 3 Before we begin… CS001 - Lecture 3 Remember Jafa (in Wolf) 4CS001- Lecture 1 2 Enter your normal username/password Some people are not.
Chapter 6 Horstmann Programs that make decisions: the IF command.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
1 Conditionals In many cases we want our program to make a decision about whether a piece of code should be executed or not, based on the truth of a condition.
School of Computing Science CMT1000 Ed Currie © Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 5B: Branch Statements - Making.
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
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
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.
Chapter 9 Interactive Multimedia Authoring with Flash - Introduction to Programming “Computers and Creativity” Richard D. Webster, COSC 109 Instructor.
Control Structures I (Selection)
EGR 2261 Unit 4 Control Structures I: Selection  Read Malik, Chapter 4.  Homework #4 and Lab #4 due next week.  Quiz next week.
Python Programming Using Variables and input. Objectives We’re learning to make use of if statements to enable code to ask questions. Outcomes Build an.
Decision Structures and Boolean Logic
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
CHAPTER 4: CONDITIONAL STRUCTURES Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
ENG 1181 College of Engineering Engineering Education Innovation Center MAT – Conditional Statements Topics: 1.Conditional statements if-end if-else-end.
B065: PROGRAMMING OPERATORS AND SELECTION 2. Starter  What do each of the following mean? Write an example of how each could be used. Symbol = <
Fortran 2- More Basics Chapter 3 in your Fortran book.
Conditional Statements ENGR 1187 MATLAB 7. Conditional Statements in Real Life A Fluorescence Activated Cell Sorter (FACS) sorts cells based on predetermined.
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: An Introduction to Programming Using Visual Basic 2012, All Rights ReservedAn Introduction.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
MS3304: Week 6 Conditional statements. Overview The flow of control through a script Boolean Logic Conditional & logical operators Basic decision making.
Decision Making Selection structures (if....else and switch/case)
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: An Introduction to Programming Using Visual Basic 2012, All Rights ReservedAn Introduction.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
22/11/ Selection If selection construct.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Introduction to Engineering MATLAB - 13 Agenda Conditional statements  If – end  If – else – end  if – elseif – else - end.
ENG 1181 College of Engineering Engineering Education Innovation Center P. 1 MAT - Conditional Statements Topics Covered: 1. if based conditional statements.
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
31/01/ Selection If selection construct.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
Python Lesson 2.
Programming Language C++ Lecture 3. Control Structures  C++ provides control structures that serve to specify what has to be done to perform our program.
Decision Making and Branching
BO65: PROGRAMMING ITERATION 1. Starter  Write down what you think the code below outputs on screen: Dim intCounter as integer intCounter = 0 Do while.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
ME 142 Engineering Computation I Condition Statements.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
Chapter 4: Making Decisions.
Chapter 4 MATLAB Programming
Exploring Computer Science Lesson 4-10 – Part 1
Topics The if Statement The if-else Statement Comparing Strings
Programming Fundamentals
Simple Control Structures
Topics The if Statement The if-else Statement Comparing Strings
Chapter 3: Introduction to Problem Solving and Control Statements
Items, Group Boxes, Check Boxes & Radio Buttons
If selection construct
If selection construct
Logical Operations In Matlab.
Chapter 5: Control Structure
Chapter 4: Control Structures I (Selection)
Conditional Logic Presentation Name Course Name
Boolean Expressions to Make Comparisons
Flowcharts and Pseudo Code
Selection Statements Chapter 3.
OPERATORS AND SELECTION 2
IPC144 Introduction to Programming Using C Week 2 – Lesson 2
Exploring Computer Science Lesson 4-10 – Part 1
Presentation transcript:

B065: PROGRAMMING OPERATORS AND SELECTION 1

Starter  Have a go at the All Logic Signs activity.  COMP1  Programming  8 Selection  All Logic Signs.xls

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

Operators Recap Answer these questions with a TRUE or FALSE 6 > 3 72 < >= > = <= 16*2 > MORE than < LESS than <= LESS than or EQUAL to >= MORE than or EQUL to

Logical Operators in Programming EvaluationSymbolExample Equal to=Number = 1 Less Than<Age < 21 Less Than or Equal To<=Age <=17 Greater Than>Debt > 25 Greater Than or Equal To>=Debt > = 2000 Not Equal To<>Number <> 1 AND Number = 1 AND Age < 12 OR Number = 1 OR Number = 2 NOT NOT Age < 17

IF Logic Recap Which goes where to make a logical sentence? Let’s do one at a time. CLICK on a question mark to reveal.

What you believe in… QuestionWhat to do if TRUEWhat to do if FALSE IF 12 > 25Clap twiceClap once IF you are at CryptStand up, then sit downSpin your head around IF 30 < 42Wink twiceShake your hands IF 12 > 6*1Put your hands upClick twice IF you are in ICTStand up, turn around, sit back down Yawn IF 4*2 >= 12Roar like a lionMoo like a cow You will be given a logical question. If you think it is TRUE, do what is says under TRUE. If you think it is FALSE, do the FALSE action.

A Separate Example Let’s look at a spreadsheet version (From GCSE) which you should be familiar with. It nicely sets the scene for selection in programming. IF Example

IF…THEN…END IF Sometimes in programming, you may only want to execute lines of code if certain conditions are met. For example, you would not send out a bill to a customer if they did not owe anything. The way to write an IF statement is simple: If Then End If

Examples If score = 100 Then Console.WriteLine("Full Marks!") End If If pay > tax Then pay = pay - tax End If If mark < 40 Then result = "Fail" console.writeline(result) End If The semantics are simple: if the condition is True, the following statement(s) will be executed; otherwise they will be omitted. If, Then, and End If are all keywords - the code editor will capitalise them and colour them blue when you finish typing any of them, as it does with all keywords.

What can you use? The statements can be any legal VB statements - and that includes If … Then … End If statements now! So we can quite easily have a nested structure, like the following example: If age > 65 Then If theDay = "Thursday" Then 'Senior Citizens get a 10% discount! cost = 0.9 * cost End If Note that each If requires a corresponding End If. See how we INDENT to make the code easier to understand.

IF…THEN…ELSE…END IF What if you want some code to be executed if the condition IS NOT met? If mark < 40 Then result = "Fail" Else result = "Pass" End If Console.WriteLine(result) You can use ELSE. What happens in the code above?

Multiple Conditions? ELSEIF What if you have multiple conditions (or rules) which you want to check?

Summary IF…END IF Basic Checks. IF…ELSE…END IFBasic Checks with a catch situation. IF…ELSEIF…ELSE…END IF Multiple conditions. You can also use logical operators ( >, >=, <, <=, AND, OR, NOT) in your selection statements.

TASK Complete the questions in your guide. Attempt Tasks 10, 11 and 12. We will go through each task throughout the lesson. Complete for homework.

Objectives Review Understand what is meant by selection in programming. Explore selection programming commands: IF 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: Read Chapter 4 Homework – Finish exercises 1-10 Chapter 4

Plenary If the day is Monday and a person is 18 or over (but younger than 21), they qualify for a discount on drinks over £2. They receive 35p off the price of the drink. What would be the IF block which would express this in code?