5.04 Apply Decision Making Structures

Slides:



Advertisements
Similar presentations
ProgressBook User Start-Up
Advertisements

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.
The If Then Else Statement Using JavaScript TIP The If Statement is the fundamental control structure that allows branches in the flow of control in a.
Microsoft® Small Basic
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.
5.04 Apply Decision Making Structures
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
COMPUTER PROGRAMMING I Understand Problem Solving Tools to Design Programming Solutions.
CS0007: Introduction to Computer Programming
Selection (decision) control structure Learning objective
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 9 Decisions, Decisions, Decisions.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Conditional Statements Introduction to Computing Science and Programming I.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
An Introduction to Textual Programming
In.  This presentation will only make sense if you view it in presentation mode (hit F5). If you don’t do that there will be multiple slides that are.
Using the selection structure (Unit 7) Visual Basic for Applications.
Bug Session Four. Session description Objectives Session activities summary Resources Prior knowledge of sequencing instructions using Bug Bug website.
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.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
CS102 Introduction to Computer Programming Chapter 4 Making Decisions.
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
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.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
COMPUTER PROGRAMMING II SUMMER 2011 Visual Basic to C#
Conditional Structures UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
22/11/ Selection If selection construct.
Decision Making CMSC 201. Overview Today we will learn about: Boolean expressions Decision making.
Decision Structures and Boolean Variables. Sequence Structures Thus far, we’ve been programming “sequence structures” Thus far, we’ve been programming.
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
COMPUTER PROGRAMMING I 5.04 Apply Decision Making Structures.
VB Conditionals If Then, Select Case. If Then Useful computer programs typically have to make a lot of decisions. In VB, If…Then code is used for decision.
An Object-Oriented Approach to Programming Logic and Design Chapter 5 Making Decisions.
Lecture 7 Conditional Scripting and Importing/Exporting.
Decision Statements, Short- Circuit Evaluation, Errors.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
Controlling Program Flow with Decision Structures.
Controlling Program Flow with Decision Structures.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
More Visual Basic Code: if-then-else, for loops Controls: Multiple forms, List Boxes, Radio buttons, frames,
CRE Programming Club - Class 3 Robert Eckstein and Robert Heard.
Computer Science Up Down Controls, Decisions and Random Numbers.
Loops Brent M. Dingle Texas A&M University Chapter 6 – Section 6.3 Multiway Branches (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Introduction to Decision Structures and Boolean Variables
5.04 Apply Decision Making Structures
Understand Problem Solving Tools to Design Programming Solutions
UNIT 5 Lesson 15 Looping.
Computer Programming I
IF statements.
Operator Precedence Operators Precedence Parentheses () unary
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
The order in which statements are executed is called the flow of control. Most of the time, a running program starts at the first programming statement,
Lesson 9: "if-else-if" and Conditional Logic
Microsoft Visual Basic 2005 BASICS
Lesson 8: Boolean Expressions and "if" Statements
Learning to Program in Python
Conditions and Ifs BIS1523 – Lecture 8.
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Visual Basic – Decision Statements
Selection Statements.
Introduction to Decision Structures and Boolean Variables
Conditional Logic Presentation Name Course Name
Programming In Lesson 4.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
True or False True or False
Presentation transcript:

5.04 Apply Decision Making Structures Computer Programming I

Objective/Essential Standard Essential Standard: 5.00- Apply Programming and Conditional Logic Indicator: 5.04 Apply decision-making structures. (3%)

What is a decision? Decisions are made by humans hundreds of times a day. Computers can make simple decisions also. What are some decisions you made today so far? Image taken from: learn2bebuddies.com

Boolean Logic Remember, from the previous section Boolean logic? (Ex: intNum = 5) Computers use it to make decisions! There are only two answers: TRUE or FALSE Computers do not know about Maybe!

The If Decision Structure

Decisions… Decisions So when you got up this morning what did you do? This is a decision. Let’s put it in computer terms. If the sun is out, then I will walk to school Image taken from: http://web.multco.us/sun/linkage

The If…Then Statement If…Then is a decision structure that executes a set of statements only when a condition is true. Form: If condition Then Statements End If T

The If…Then Statement IF the sun is out (question) THEN I will walk to school. Remember the computer uses Boolean logic (T/F). So either the sun is out (true) or ANY other state (false). No maybes or in-betweens. When the question is True, the statements after THEN (and down to ENDIF) execute. They are skipped if the question is False.

The If…Then Statement Let’s say there was a program that determined whether or not a number was guessed correctly.  Further assume that the ‘correct’ number was 5.  A conditional statement could be set up to notify the user if he/she guessed the correct answer: In the above code, intGuess=5 represents the condition. The condition is the code statement that needs to be true in order for VB to execute the code between the If and the End If.  The = sign is called a conditional operator (more on this later).  Essentially, if the condition is true, the statements between the If and the End If statements are performed; if the condition is false, VB skips those lines and continues on with code that appears after the block of code. 

The If…Then Statement You will also notice that, when you type the first line of the conditional statement, and press Enter, the next line automatically indents.  While this doesn’t have any impact on the way the VB reads or executes the code, it serves as an easier way for programmers to read and understand the code structure (other coding structures are indented in this way).  VB also automatically adds the End If line.  This indentation scheme should always be used with conditional statements.

IF..THEN..ELSE Statement In Visual Basic we use the IF..THEN..ELSE statement to tell the computer we want it to make a decision. For example If a = b then c= 10 Else c=13 End If Remember in C# that = is the assignment operator and is NOT used for comparisons of equality. A double equal (==) must be used to check for equality. This is not a requirement is VB and using == will produce an error. T F

Use of the ELSE NOTE: Else is optional- if omitted and the “question” is false no action is taken. If ELSE is used, the statements after the ELSE will execute if the “question” is NOT true (Boolean FALSE) If…Then…Else statements are used when the programmer needs to choose between two different outcomes.  For example:

IF..THEN and IF..THEN..ELSE Statements What’s next? In the formative assessment, you will complete a series of steps designed to help you understand the concepts developed in this lesson.  Please follow each step as documented. If you have issues/questions, make sure you watch the videos to gain a better understanding.