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.

Slides:



Advertisements
Similar presentations
Chapter 4: Control Structures I (Selection)
Advertisements

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 5 Selection Statements Animated Version.
Chapter 4 Decision Making Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E. Reingold.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 5 Selection Statements.
Control Flow Statements: Repetition/Looping
Computer Programming 12 Mr. Jean April 2 nd, 2014.
Logical Operators and While Loops CS303E: Elements of Computers and Programming.
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
CSC 142 G 1 CSC 142 Conditionals [Reading: chapter 5]
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.
Overview Program flow Decision / branching / selection structures True & False in Python Comparison operators & Boolean expressions if … if … else if …
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Section 4.2: Functions that Test Conditions (continued)
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
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.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
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.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Conditional Statements While writing a program, there may be a situation when you need to adopt one path out of the given two paths. So you need to make.
Institute for Personal Robots in Education (IPRE)‏ CSC 170 Computing: Science and Creativity.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
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.
Control Structures 1. Control Structures Java Programming: From Problem Analysis to Program Design, D.S. Malik 2.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
Basic Conditions. Challenge: ● Ask the user his/her name ● If it’s “Wally,” jeer him ● Pause video and try on your own.
Visual Basic CDA College Limassol Campus COM123 Visual Basic Programming Semester C Lecture:Pelekanou Olga Week 4: Understand and implement Decisions.
If statement.  It is made up of three main components:  The keyword itself,  an expression that is tested for its truth value,  and a code suite to.
Computer Science 101 If Statement. Python Relational Operators.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
CS305j Introduction to Computing More Conditional Execution 1 Topic 13 More Conditional Execution " Great dancers are not great because of their technique;
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
Random Functions Selection Structure Comparison Operators Logical Operator
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
 Type Called bool  Bool has only two possible values: True and False.
Follow up from lab See Magic8Ball.java Issues that you ran into.
Control Flow (Python) Dr. José M. Reyes Álamo.
Sequence, Selection, Iteration The IF Statement
Loops in Java.
C-Language Lecture By B.S.S.Tejesh, S.Neeraja
Control Structures.
Lesson 8: Boolean Expressions and "if" Statements
Computers & Programming Languages
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Pages:51-59 Section: Control1 : decisions
Chapter 8: More on the Repetition Structure
Visual Basic – Decision Statements
Selection Statements.
Conditional Statements
Conditional Logic Presentation Name Course Name
Types, Truth, and Expressions (Part 2)
ICT Programming Lesson 3:
Conditionals.
Understanding Conditions
Seating “chart” Front - Screen rows Back DOOR.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
PROGRAM FLOWCHART Iteration Statements.
Pages:51-59 Section: Control1 : decisions
Types, Truth, and Expressions
Chapter 3: Selection Structures: Making Decisions
PHP CONDITIONAL STATEMENTS
Presentation transcript:

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 based on information that we receive. (There is not one solution for all problems!) As such we need a way to have the computer make decisions. As such we need a way to have the computer make decisions.

Decision Structures There are different types of decision structures for us to chose from: If / Else if / Else If / Else if / Else Case Case

If / Else Structures This structure allows us to make a decision based on the truthfulness of a boolean expression. If the expression is true then the first block of code is executed If the expression is true then the first block of code is executed If the expression is false then the second block will be evaluated If the expression is false then the second block will be evaluated

Syntax The syntax for the if /else if / else structure is: if (boolean_expression) { this block evaluates if the expression is true } else if (second boolean expression) { this block evaluates if the second expression is true }else { This block executes if none of the boolean expressions is true }

Example if (age <16) {cout << You may not drive; } else if (age > 65) { cout << You must get your eyes checked every year to keep your license; }else { cout << You have no restrictions on your license; }

Exceptions If the code in a block has only one command then the curly braces are not required: if (age <16) cout << You may not have a drivers license; else if (age > 65) cout << You must get your eyes checked every year to keep your license; else cout << You have no restrictions on your license;

Exercise Create a program that uses the if else structure to make a decision based on the users input. Create a program that uses the if else structure to make a decision based on the users input. Write a program that acts like a multiple choice quiz Write a program that acts like a multiple choice quiz