Understanding Conditions

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 Decision Making Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E. Reingold.
PHYS707: Special Topics C++ Lectures Lecture 2. Summary of Today’s lecture: 1.More data types 2.Flow control (if-else, while, do-while, for) 3.Brief introduction.
The "if structure" is used to execute statement(s) only if the given condition is satisfied.
Conditional Statements Introduction to Computing Science and Programming I.
If Statements & Relational Operators Programming.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 9/15/06CS150 Introduction to Computer Science 1 Combined Assignments, Relational Operators, and the If Statement.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
1 CS 105 Lecture 4 Selection Statements Wed, Jan 26, 2011, 6:05 pm.
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,
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
General Computer Science for Engineers CISC 106 Lecture 33 Dr. John Cavazos Computer and Information Sciences 05/11/2009.
The If/Else Statement, Boolean Flags, and Menus Page 180
CPS120: Introduction to Computer Science Decision Making in Programs.
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.
CS31: Introduction to Computer Science I Discussion 1A 4/9/2010 Sungwon Yang
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Choices and Decisions if statement if-else statement Relational.
1 09/15/04CS150 Introduction to Computer Science 1 Life is Full of Alternatives Part 2.
© 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.
Conditions, Logical Expressions, and Selection Control Structures ROBERT REAVES.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
CPS120: Introduction to Computer Science Decision Making in Programs.
CPS120: Introduction to Computer Science Decision Making in Programs.
1 9/26/05CS150 Introduction to Computer Science 1 Life is Full of Alternatives.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 4 Making Decisions.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
 Type Called bool  Bool has only two possible values: True and False.
The Ohio State University
Chapter 4: Making Decisions.
Bools & Ifs.
JavaScript conditional
Topics The if Statement The if-else Statement Comparing Strings
Computers & Programming Languages
Types, Truth, and Expressions (Part 2)
Unary Operators ++ and --
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Chapter 4: Decision Structures and Boolean Logic
Pages:51-59 Section: Control1 : decisions
Summary Two basic concepts: variables and assignments Basic types:
If Statements.
Computer Science Core Concepts
Conditional Statements
Types, Truth, and Expressions (Part 2)
Decision I (if Statement)
CS150 Introduction to Computer Science 1
Life is Full of Alternatives
CS150 Introduction to Computer Science 1
Relational Operators.
Nate Brunelle Today: Conditional Decision Statements
CS150 Introduction to Computer Science 1
Life is Full of Alternatives
Life is Full of Alternatives
CS150 Introduction to Computer Science 1
Pages:51-59 Section: Control1 : decisions
Chapter 4: Decision Structures and Boolean Logic
Life is Full of Alternatives Part 3
Conditionals.
Presentation transcript:

Understanding Conditions x and y are greater than z Expression? When true? x is equal to 1.0 or 3.0 x is the range z to y inclusive x is outside the range z to y 4/8/2019 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Boolean variables Boolean variables have value true or false Can assign them: bool same; same = false; same = (x == y); cout << “The value of same is” << same; 4/8/2019 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 If statements Single alternative: if (condition) or if (condition) statement; { next statement; statements; } next statement; If condition is true, statement(s) following if execute if condition is false, statement(s) following if are skipped. 4/8/2019 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Examples if (x >= 0) cout << “x is positive” << endl; if (x < 0) x = -x; if ((x == 0) && (y == 0)) { x = 1; y = 1; } 4/8/2019 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Two Alternative if (condition) if (condition) statementT; { else statementsT; statementF; } else { statementsF; } 4/8/2019 CS150 Introduction to Computer Science 1