Multi-Selection If-elsif Statement.  In fact, it’s everything in between  Yesterday we learned how to add a control statement that gave us two path.

Slides:



Advertisements
Similar presentations
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Advertisements

Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
CS 106 Introduction to Computer Science I 02 / 11 / 2008 Instructor: Michael Eckmann.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
An Introduction to Programming with C++ Fifth Edition Chapter 6 More on the Selection Structure.
Logo Lesson 5 TBE Fall 2004 Farah Fisher. Prerequisites  Given a shape, use basic Logo commands and/or a procedure to draw the shape, with and.
1 Arithmetic in C. 2 Type Casting: STOPPED You can change the data type of the variable in an expression by: (data_Type) Variable_Name Ex: int a = 15;
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
CIS101 Introduction to Computing Week 12 Spring 2004.
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
Chapter 9 IF Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Chapter 2 - Algorithms and Design
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
While Loops Indefinite Iteration. Last lesson we looked at definite loops using the ‘For’ statement. The while loop keeps going while some condition is.
CSC 204 Programming I Loop I The while statement.
Chapter 4 Selection Structures: Making Decisions.
Agenda Exam #1 Review Modulus Conditionals Boolean Algebra Reading: Chapter Homework #5.
Conditional Execution
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.
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
1 Chapter 2 - Algorithms and Design print Statement input Statement and Variables Assignment Statement if Statement Flowcharts Flow of Control Looping.
MULTIPLE ALTERNATIVES IF… THEN… ELSEIF SELECT CASE.
If Statements If statements: allow the computer to make a decision Syntax: if (some condition) { then do this; } else { then do that; } no semicolons on.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Lecture 3 – Selection. Outline Recall selection control structure Types of selection One-way selection Two-way selection Multi-selection Compound statement.
Conditional Structures UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
CHAPTER#3 PART1 STRUCTURED PROGRAM DEVELOPMENT IN C++ 2 nd semester King Saud University College of Applied studies and Community Service Csc.
CHAPTER#3 PART1 STRUCTURED PROGRAM DEVELOPMENT IN C++ 2 nd semester King Saud University College of Applied studies and Community Service Csc.
1 ball, 2 ball, red ball, blue ball By Melissa Dalis Professor Susan Rodger Duke University June 2011.
22/11/ Selection If selection construct.
The IF-statements 31-Jan-2005 Venkatesh Ramamoorthy.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
PEG200/Saidatul Rahah 1.  Selection Criteria › if..else statement › relational operators › logical operators  The if-then-else Statement  Nested if.
Selection Statements. Introduction Today we learn more about learn to make decisions in Turing ▫Nested if statements, ▫case statements.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Conditional Statements.  Quiz  Hand in your jQuery exercises from last lecture  They don't have to be 100% perfect to get full credit  They do have.
Chapter#3 Part1 Structured Program Development in C++
31/01/ Selection If selection construct.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
FLOW OF CONTROL In C++ the program execution starts with the first statement in the main() and ends with the last statement of main(). This is called.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
CONDITIONALS CITS1001. Scope of this lecture if statements switch statements Source ppts: Objects First with Java - A Practical Introduction using BlueJ,
 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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
JavaScript – If/Else contd
INC 161 , CPE 100 Computer Programming
Factoring if/else code
Microsoft Visual Basic 2005 BASICS
Control Statement Examples
Selection CIS 40 – Introduction to Programming in Python
Conditional Statements
Conditions and Ifs BIS1523 – Lecture 8.
More Loops.
Module 4 Loops.
Visual Basic – Decision Statements
Selection Statements.
Chapter 3: Selection Structures: Making Decisions
Programming Concepts and Database
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Chapter 3: Selection Structures: Making Decisions
Chapter 3: Selection Structures: Making Decisions
Module 3 Selection Structures 6/25/2019 CSE 1321 Module 3.
Programming Fundamental
Presentation transcript:

Multi-Selection If-elsif Statement

 In fact, it’s everything in between  Yesterday we learned how to add a control statement that gave us two path choices in our program, if-else  This is great, but rarely in life or programs is there only two choices to choose between.  Introducing multi-selection, allowing infinite choices  The if-elsif statement is exactly the same as an if-else statement except it allows us to add more choices in between the if and the else. Life is not Black and White

if ( ) then % Code to execute if the in brackets is true. elsif ( ) then % Code to execute if the in brackets is true AND ALL % expressions above it is false elsif ( ) then % Code to execute if the in brackets is true AND ALL % expressions above it are false else % Code to execute if all ’s above are false. end if The if-elsif Statement

var denominator : int get denominator if ( denominator = 0 ) then % if the number is 0 put “The number is not divisible.” elsif (denominator > 0 ) then % if the number is positive and divisible put “The number is divisible and positive.” else % if the number is negative and divisible put “The number is divisible and negative.” end if Example

 Only the FIRST block that evaluates to true will be executed, all others, even if true, will be skipped  Order of test expressions is important since only the first true expression is entered  Each if-elsif statement only has ONE if  The else statement is optional  The number of elsif’s can be from 0 to infinite Special Notes

 Create a program that asks and stores the user for their current mark.  The program should then use that mark and output a specific message stating what level they are at in a complete sentence. Below is a chart with the message that corresponds with the grades. For this question you will have to use a compound if statement, that means using either AND or OR. Practice MarkOutput Text Between 80 and 100Level 4 Between 70 and 79Level 3 Between 60 and 69Level 2 Between 50 and 59Level 1 Between 1 and 49Level R 0Level I

 Question 2: The Guessing Game Part 2  Recreate the Guessing game, but this time your program will be between 1 and 100 and do more than just tell them to guess higher or lower  It must now calculate how far away the user’s guess is from the random number and display the appropriate statement depending on the distance away.  Right on: “You win!”  Within 2: “Red hot”  Within 5: “Steaming hot”  Within 10: “Warm”  Within 20: “Cool”  More than 20: “Ice cold”  HINT: You will need to use the mathematical concept of an absolute value, what this is, is that it takes any number positive or negative and gives you the positive version as a result.  This is useful when calculating the difference between two numbers and you do not know which number is larger.  To use absolute value in Turing we have a new function to use, abs(value : int)  E.g. var myValue : int := abs(-5.4) Practice