Lesson 5 - Decision Structure By: Dan Lunney

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

If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
Nested if-else Statements.  Should be indented to make the logic clear.  Nested statement executed only when the branch it is in is executed. For example,
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
1 Software Development Programming Language Features – Branching.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Selection (decision) control structure Learning objective
Understanding the Three Basic Structures
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture two Dr. Hamdy M. Mousa.
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
Selection Logic Building decision-making into programs.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
1 Selection Structures. 2 Making Decisions Sample assignment statements to figure worker pay with possible overtime PayAmount = Hours * Rate PayAmount.
Copyright © 2012 Pearson Education, Inc. Chapter 6 Problem Solving with Decisions Problem Solving and Programming Concepts 9 th Edition By Maureen Sprankle.
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
Agenda Control Flow Statements Purpose test statement if / elif / else Statements for loops while vs. until statements case statement break vs. continue.
Programming Logic and Design Sixth Edition
CPS120: Introduction to Computer Science Decision Making in Programs.
Problem Solving with Decisions
Conditionals & boolean operators
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
CPS120 Introduction to Computer Programming The Programming Process.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
PROBLEM SOLVING WITH LOOPS Chapter 7. Concept of Repetition Structure Logic It is a computer task, that is used for Repeating a series of instructions.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Control Structures CPS120: Introduction to Computer Science Lecture 5.
Python Selection. All the programs you have been developing so far have been sequential, this means that each instruction is executed in a set order.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
Problem Solving with Decisions
Conditions, Logical Expressions, and Selection Control Structures ROBERT REAVES.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding the Three Basic Structures Structure: a basic unit of programming logic Any program.
CPS120: Introduction to Computer Science Decision Making in Programs.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
ARITHMETIC OPERATORS COMPARISON/RELATIO NAL OPERATORS LOGIC OPERATORS ()Parenthesis>Greater than &&And ^Exponentiation=>=
Lesson thirteen Conditional Statement "if- else" ©
3.1.3 Program Flow control Structured programming – SELECTION in greater detail.
Programming Logic and Design Fifth Edition, Comprehensive
CPS120: Introduction to Computer Science Decision Making in Programs.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
Problem Solving with Decission Structure
Programming Logic and Design Fourth Edition, Introductory Chapter 2 Understanding Structure.
Control Flow (Python) Dr. José M. Reyes Álamo.
CHAPTER 5: SELECTION STRUCTURES: if and switch STATEMENTS
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
CHAPTER 5: SELECTION STRUCTURES: if and switch STATEMENTS
Programming Fundamentals
Using the Priming Read Priming read (or priming input):
Selection By Ramin && Taimoor
CPS120: Introduction to Computer Science
Computers & Programming Languages
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Understanding the Three Basic Structures
Design and Implementation
` Structured Programming & Flowchart
Three Special Structures – Case, Do While, and Do Until
Visual Basic – Decision Statements
Programs as Directions
Computer Science Core Concepts
ICT Programming Lesson 3:
ICT Gaming Lesson 2.
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
WRITING AN ALGORITHM, PSEUDOCODE, AND FLOWCHART LESSON 2.
Presentation transcript:

Lesson 5 - Decision Structure By: Dan Lunney Computer Programming 12 Lesson 5 - Decision Structure By: Dan Lunney

If /Then / Else statement Decision logic structure is used to make a decision that has 2 outcomes: true or false We test which it is by using the if/then/else statement IF <condition> THEN <True set of instructions> ELSE <False set of instructions>

If/Then/Else Flowchart Start IF <condition (s)> TRUE FALSE Instructions if conditions are false Instructions if conditions are true Exit

Nested If/Then/Else We can have a second if/then/else statement as the set of instructions for the True and/or False condition of another if/the/else statement This is called a nested if/then/else

Nested If/Then/Else Flowchart Start FALSE TRUE if FALSE TRUE if Instructions Instructions Instructions

Three Types of Logic Straight-through (no else part) Positive Logic Negative Logic

Straight-Through Logic All if statements are executed sequentially There is no ELSE branch to be executed This type of logic is the least efficient because we need to write a code statement for every possible decision

Straight Logic Flowchart IF F T IF F T IF F

Positive Logic Most common type as this is how we think Continues to processing decisions until a decision is true then it stops executing

Positive Logic Flowchart Start TRUE FALSE if TRUE FALSE if Instructions Instructions Instructions Exit

Negative Logic Works the opposite as Positive Logic Continues to process decisions until a decision is false then it stops executing

Negative Logic Flowchart Start FALSE TRUE if FALSE TRUE if Instructions Instructions Instructions

Sample Problem – Lesson 5 What would the flowcharts and algorithms of the following problem look like in straight logic, positive logic, and negative logic? People pay $7 for movies if they are under 16, $10 if they are between 16 and 65, and they pay $5 if they are greater than 65. See sample problem sheet