IF Statements flowcharts and pseudocode Please open the speaker notes - they contain additional information!

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
IF statement (i) Single statement. IF ( logical expression ) statement Example: read(*,*) a if (a. lt. 0) a = -a write(*,*) a Or read(*,*) a if (a < 0)
Computer Programming 12 Mr. Jean April 2 nd, 2014.
If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.
Machine Instructions Control Flow 1 ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-1B.ppt Modification date: March 24, 2015.
Making Decisions in Python Sec 9-10 Web Design. Objectives The student will: Understand how to make a decision in Python Understand the structure of an.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
PSEUDOCODE & FLOW CHART
Lesson 5 - Decision Structure By: Dan Lunney
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 9 Decisions, Decisions, Decisions.
Selection Logic Building decision-making into programs.
Conditional Statements Introduction to Computing Science and Programming I.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
True/False. False True Subject May Go Here True / False ? Type correct answer here. Type incorrect answer here.
1 Selection Structures. 2 Making Decisions Sample assignment statements to figure worker pay with possible overtime PayAmount = Hours * Rate PayAmount.
Determine whether each curve below is the graph of a function of x. Select all answers that are graphs of functions of x:
Queries and SQL in Access Please use speaker notes for additional information!
Local Definitions, Scope, Functional Abstraction, and Polymorphism.
Chapter 9 IF Statement Bernard Chen. If Statement The main statement used for selecting from alternative actions based on test results It’s the primary.
1 Spreadsheets SELECTION. 2 Aims  Understand the principles of selection in Excel  Examine the basic IF statement format  Look into Nested IF statements.
CSci 125 Lecture 10 Martin van Bommel. Simple Statements Expression followed by semicolon Assignments total = n1 + n2; Function calls printf(”Hello.\n”);
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.
Computer Science Selection Structures.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Logic Structure - focus on looping Please use speaker notes for additional information!
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.
Practice 1.2 Answers
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
Chapter 5 - VB 2005 by Schneider1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks.
A Simple Quiz: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009, added Part 2 July 2011.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Type your question here. Type Answer Type your question here. Type Answer.
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
Finish ing the logic flowc harts from week 3.. if invcd = “A” and (amtfst > 500 or amtsnd > 200) move “OKAY” to msg end if With the parenthesis, invcd.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Two file sequential file processing (maximum 1 record per id on each file) Please use speaker notes for additional information!
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
IF STATEMENTS AND BOOLEAN EXPRESSIONS. BOOLEAN EXPRESSIONS Evaluate to a value of true or false Use relational or equivalence operators Boolean operators.
SELECTION CONTROL STRUCTURE Prepared by: Careene McCallum-Rodney.
Sensor Information: while loops and Boolean Logic.
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
Conditional or Decision Logic
Sequence, Selection, Iteration The IF Statement
Simple Control Structures
Chapter 4: Decision Structures and Boolean Logic
And the text with form..
Access and Condition Statements
ICS 3U Tuesday, September 21st.
Chapter 4: Decision Structures and Boolean Logic
Chapter 8: More on the Repetition Structure
Visual Basic – Decision Statements
MATLAB Logical Expressions
Chapter 5: Control Structure
Conditional Logic Presentation Name Course Name
X Bad 1 Bad 2 Bad 3 Good 1 Good 2 Good 3 Question
If statements (Inven1, Inven2, Inven2a, Inven3, Inven3a)
Programming Concepts and Database
LI4 Inequalities- True or False?.
More on If statements (Calculate, Calculate1, Calculate2)
Chapter 4: Decision Structures and Boolean Logic
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.
JavaScript IF assignment two
True or False True or False
The boolean type and boolean operators
Conditionals.
Presentation transcript:

IF Statements flowcharts and pseudocode Please open the speaker notes - they contain additional information!

Simple IF - processing on Y only IF AMT > 5000 Y AMT x 10 = ANS N if amt > 5000 ans = amt * 10 end if

Simple IF - processing on Y or N IF AMT > 5000 Y ANS= AMT x 10 N ANS = AMT x 5 In this example, if the AMT is greater than 5000 then we want to multiply AMT by 10 and store the answer in ANS. If the AMT is not greater than 5000 then we want to multiply AMT by 5 and store the answer in ANS. if amt > 5000 ans = amt * 10 else ans = amt * 5 end if

IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF AMT > 5000 Y N AND relationship if invcd = “A” if amt > 5000 move “OKAY to msg end if Both statements must be true for the msg to receive the word OKAY. If either statement is false, no processing is done.

IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF AMT > 5000 Y N AND relationship if invcd = “A” if amt > 5000 move “OKAY to msg end if if invcd = “A” and amt > 5000 move “OKAY” t0 msg end if

IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF AMT > 5000 Y N AND relationship if invcd = “A” if amt > 5000 move “OKAY to msg else move “PROBLEM” to msg end if else move “PROBLEM” to msg end if if invcd = “A” and amt > 5000 move “OKAY” to msg else move “PROBLEM” to msg end if MOVE “PROBLEM” TO MSG MOVE “PROBLEM” TO MSG

IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF AMT > 5000 Y N AND relationship if invcd = “A” if amt > 5000 move “OKAY to msg else move “PROBLEM” to msg end if MOVE “PROBLEM” TO MSG

IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF AMT > 5000 Y N AND relationship if invcd = “A” if amt > 5000 move “OKAY to msg else move “PROBLEM” to msg end if else move “BAD CODE” to msg end if MOVE “PROBLEM” TO MSG MOVE “BAD CODE” TO MSG

IF INVCD = “A” Y MOVE “OKAY” TO MSG IF AMT > 5000 Y N N MOVE “OKAY” TO MSG OR relationship if invcd = “A” move “OKAY” to msg else if amt > 5000 move “OKAY” to msg end if One or the other of the if questions must be true for OKAY to be moved to msg.

IF INVCD = “A” Y MOVE “OKAY” TO MSG IF AMT > 5000 Y N N MOVE “OKAY” TO MSG OR relationship if invcd = “A” move “OKAY” to msg else if amt > 5000 move “OKAY” to msg end if if invcd = “A” or amt > 5000 move “OKAY to msg end if

IF INVCD = “A” Y MOVE “OKAY” TO MSG IF AMT > 5000 Y N N MOVE “OKAY” TO MSG MOVE “PROBLEM” TO MSG OR relationship if invcd = “A” move “OKAY” to msg else if amt > 5000 move “OKAY” to msg else move “PROBLEM” to msg end if

IF INVCD = “A” Y MOVE “OKAY” TO MSG IF AMT > 5000 Y N N MOVE “OKAY” TO MSG OR relationship if invcd = “A” move “OKAY” to msg else if amt > 5000 move “OKAY” to msg else move “PROBLEM” to msg end if if invcd = “A” or amt > 5000 move “OKAY to msg else move “PROBLEM” to msg end if MOVE “PROBLEM” TO MSG

IF INVCD = “A” Y MOVE “AMT - OKAY” TO MSG IF AMT > 5000 Y N N MOVE “CODE - OKAY” TO MSG MOVE “PROBLEM” TO MSG OR relationship if invcd = “A” move “CODE - OKAY” to msg else if amt > 5000 move “AMT - OKAY” to msg else move “PROBLEM” to msg end if

cond1 AND (cond 2 OR cond3) IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF AMTFST > 500 Y N IF AMTSND > 200 MOVE “OKAY” TO MSG YN if invcd = “A” if amtfst > 500 move “OKAY” to msg else if amtsnd > 200 move “OKAY” to msg end if

cond1 AND (cond 2 OR cond3) IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF AMTFST > 500 Y N IF AMTSND > 200 MOVE “OKAY” TO MSG YN if invcd = “A” and (amtfst > 500 or amtsnd > 200) move “OKAY” to msg end if Note the use of parenthesis here. In boolean logic AND gets resolved before OR. That means if we did not have the parenthesis, it would treat this like invcd = A and amtfst > 500 or just amtsnd > 200. We want the logic to be invcd = A and either amtfst > 500 or amtsnd >200. To do this, we need to change the order of operation so that the two things in the or relationship are grouped together. We do this by using parenthesis. Continue below

IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF AMTFST > 500 Y N IF AMTSND > 200 MOVE “OKAY” TO MSG YN if invcd = “A” if amtfst > 500 or amtsnd > 200 move “OKAY” to msg end if cond1 AND (cond 2 OR cond3)

IF INVCD = “A” Y MOVE “OKAY” TO MSG N IF AMTFST > 500 YN IF AMTSND > 200 MOVE “OKAY” TO MSG YN cond1 AND cond 2 OR cond3 IF AMTSND > 200 MOVE “OKAY” TO MSG YN if invcd = “A” and amtfst >500 or amtsnd > 200 move “OKAY” to msg end if

IF AMTSND > 200 MOVE “OKAY” TO MSG YN cond3 OR cond1 AND cond2 IF INVCD = “A” Y N IF AMTFST > 500 YN MOVE “OKAY” TO MSG if amtsnd > 200 or invcd = “A” and amtfst > 500 move “OKAY” to msg end if

cond1 AND (cond 2 OR cond3) IF INVCD = “A” Y MOVE “ >500 - OKAY” TO MSG N IF AMTFST > 500 YN IF AMTSND > 200 MOVE “>200 -OKAY” TO MSG YN if invcd = “A” if amtfst > 500 move “>500 - OKAY” to msg else if amtsnd > 200 move “>200 -OKAY” to msg else move “PROBLEM” to msg end if MOVE “PROBLEM” TO MSG

cond1 AND (cond 2 OR cond3) IF INVCD = “A” Y MOVE “ >500 - OKAY” TO MSG N IF AMTFST > 500 YN IF AMTSND > 200 MOVE “>200 -OKAY” TO MSG YN if invcd = “A” if amtfst > 500 move “>500 - OKAY” to msg else if amtsnd > 200 move “>200 -OKAY” to msg else move “PROBLEM” to msg end if else move “CODE PROBLEM” to msg end if MOVE “PROBLEM” TO MSG MOVE “CODE PROBLEM” TO MSG