Basic Conditions. Challenge: ● Ask the user his/her name ● If it’s “Wally,” jeer him ● Pause video and try on your own.

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.
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
CS0007: Introduction to Computer Programming
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
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.
If Statements Sections 1.25, Control Structures o All code thus far executes every line of code sequentially o We want to be able to repeat,
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
If statements Chapter 3. Selection Want to be able to do a statement sometimes, but not others if it is raining, wear a raincoat. Start first with how.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
THE BIG PICTURE. How does JavaScript interact with the browser?
Decision Structures and Boolean Logic
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
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.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Making Decisions. 4.1 Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >= Greater than.
PHY281Flow ControlSlide 1 Decisions In this section we will learn how to make decisions in a Java program  if Statements  if... else Statements  Comparison.
MULTIPLE ALTERNATIVES IF… THEN… ELSEIF SELECT CASE.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Making Decisions.
1 2. Program Construction in Java. 2.4 Selection (decisions)
Decisions  Relational operators  Operate on two numbers or two Strings  ==, !=, >, >=,
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Introduction to branching.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Chapter Making Decisions 4. Relational Operators 4.1.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
Decision Structures, String Comparison, Nested Structures
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 3 Decision Trees Conditionals.
These Guys? Wait, What? Really?  Branching is a fundamental part of programming  It means taking an action based on decision  The decision is dependent.
Computer Science 1000 Algorithms III. Multiple Inputs suppose I ask you to write a program that computes the area of a rectangle area = length * width.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
Variables, operators, canvas, and multimedia Dr. Reyes.
Today… Operators, Cont. Operator Precedence Conditional Statement Syntax. Winter 2016CISC101 - Prof. McLeod1.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
IF STATEMENTS AND BOOLEAN EXPRESSIONS. BOOLEAN EXPRESSIONS Evaluate to a value of true or false Use relational or equivalence operators Boolean operators.
 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.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
 Type Called bool  Bool has only two possible values: True and False.
Chapter 4: Making Decisions.
Chapter 4: Making Decisions.
Topics The if Statement The if-else Statement Comparing Strings
If, else, elif.
Chapter 4: Making Decisions.
Control Structures.
Microsoft Visual Basic 2005 BASICS
Topics The if Statement The if-else Statement Comparing Strings
Computers & Programming Languages
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Pages:51-59 Section: Control1 : decisions
Selection Statements.
Computer Science Core Concepts
An Introduction to Linux
Programming Concepts and Database
Understanding Conditions
CS2011 Introduction to Programming I Selections (I)
Relational Operators.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Simple Branches and Loops
Pages:51-59 Section: Control1 : decisions
Intro to Programming (in JavaScript)
Presentation transcript:

Basic Conditions

Challenge: ● Ask the user his/her name ● If it’s “Wally,” jeer him ● Pause video and try on your own.

Conditional Branching ● Allows the computer to “make decisions” ● Based on a condition ● Embedded into some other programming structure

Condition ● Expression ● Can be evaluated to true or false ● Often compares a variable to a value ● Sometimes compares two variables

Comparison Operators ● == Equals ● != Not Equal ● <= Less than or equal to ● >= Greater than or equal to ● < Less than ● > Greater than

If Statement ● Checks a condition ● Begins a block of code ● If condition is true, executes all code in block ● If condition is false, skips code block

If example ● If it’s raining: – Wear a raincoat ● End if

Challenge Algorithm New program hiWally by me New variable userName string starts with “” Ask user’s name, store in userName If userName is equal to “Wally” Output “You Bovine” End if End Program

Challenge ● Modify the Wally program so it says one thing if the user’s name is Wally, and a more benign greeting if it’s someone else ● Pause video and try on your own…

Using an Else Clause ● Else is a useful addition to If statements. ● Else allows you to set up another block of code to execute if the condition is false

If-Else Example ● If it’s raining: – Wear a raincoat ● Else – Wear a sweater ● End if

Challenge Algorithm New program wallyOrNot by me New variable userName string starts with “” Ask user’s name, store in userName If userName is equal to “Wally” Output “You Bovine” Else Output “Do I know you” + userName + “?” End if End Program

Challenge Algorithm

Code ● My code