The C++ IF Statement Part 2 Copyright © Curt Hill

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 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
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.
The "if structure" is used to execute statement(s) only if the given condition is satisfied.
Solving Multi-Step Equations with Like Terms and Parentheses.
Copyright © Cengage Learning. All rights reserved. 6 Equations and Formulas.
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
2-1 Making Decisions Sample assignment statements PayAmount = Hours * Rate PayAmount = 40*Rate + (Hours – 40)*Rate*1.5.
Decision Making George Mason University. Today’s topics 2 Review of Chapter 2: Decision Making Go over exercises Decision making in Python.
Copyright © 2010 Pearson Education, Inc. All rights reserved Sec Set Operations and Compound Inequalities.
Copyright © Curt Hill Truth Tables A way to show Boolean Operations.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (Switch, do-while, break) Outline 4.7The.
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.
Logic Disjunction A disjunction is a compound statement formed by combining two simple sentences using the word “OR”. A disjunction is true when at.
Copyright Curt Hill A Quick Introduction to Looping Breadth not Depth.
Copyright © 2014, 2010, 2007 Pearson Education, Inc. 1 1 Chapter 9 Quadratic Equations and Functions.
Equations Reducible to Quadratic
TABLES AND VALUES Section 1.5. Open Sentence Equation.
Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential.
Copyright © Curt Hill The IF Revisited If part 4 Style and Testing.
Copyright Curt Hill The C/C++ switch Statement A multi-path decision statement.
Chapter 2 Copyright © 2015, 2011, 2007 Pearson Education, Inc. Chapter Copyright © 2015, 2011, 2007 Pearson Education, Inc. Chapter 2-1 Solving Linear.
Copyright © Curt Hill The C++ IF Statement The most important decision statement Part 1.
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
Pascal Programming George Boole, a 19 th Century mathematician, is created with true, false logic. A Boolean expression in Pascal will be true or false.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Batch Files More flow of control Copyright © by Curt Hill.
Copyright © Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
IF STATEMENTS AND BOOLEAN EXPRESSIONS. BOOLEAN EXPRESSIONS Evaluate to a value of true or false Use relational or equivalence operators Boolean operators.
Copyright © Curt Hill The C++ IF Statement More important details More fun Part 3.
The for Statement A most versatile loop
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
EQUATION IN TWO VARIABLES:
Sequence, Selection, Iteration The IF Statement
More important details More fun Part 3
Welcome to Computer Science Jeopardy
A mechanism for deciding whether an action should be taken
2.1 Propositions and Logical Operations
Chapter 4 MATLAB Programming
Operator Precedence Operators Precedence Parentheses () unary
Decision Making in Code Logical Tests & Truth Logical Expressions
Topics The if Statement The if-else Statement Comparing Strings
Organizing common actions
10 Real Numbers, Equations, and Inequalities.
Topics The if Statement The if-else Statement Comparing Strings
2-1 Making Decisions Sample assignment statements
The most important decision statement
Solving Equations with Variables on Both Sides Day 2
Program Flow Control Selection & repetition
Logical Operations In Matlab.
Visual Basic – Decision Statements
Conditional Logic Presentation Name Course Name
Tracing What, How, and Why Copyright © Curt Hill,
Solving Equations with Variables on Both Sides 1-5
More axioms Disjunction Copyright © 2007 Curt Hill.
There are infinite solutions to the system.
The Java switch Statement
Understanding Conditions
CS2011 Introduction to Programming I Selections (I)
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Truth tables Mrs. Palmer.
Solving Equations with Variables on Both Sides Day 2
The IF Revisited A few more things Copyright © Curt Hill.
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
The IF Revisited A few more things Copyright © Curt Hill.
Methods Scope How are names handled?
Methods Coding in Java Copyright © Curt Hill.
While and Do While Syntax, semantics and examples
Presentation transcript:

The C++ IF Statement Part 2 Copyright © 2004-2012 Curt Hill Not much left should be merged into 1 or 3 Copyright © 2004-2012 Curt Hill

What else is there to know? More forms of the if? More forms of the condition? More Boolean information? Copyright © 2004-2012 Curt Hill

Two forms of if statement if (boolean) statement if (boolean) statement else statement Copyright © 2004-2012 Curt Hill

The Else There is no THEN like in Pascal or BASIC The else is optional The statement to do if condition is true immediately follows the parenthesized condition The else is optional Else is a reserved word and signals the start of the statement to execute if the condition is false The if without an else means else do nothing Copyright © 2004-2012 Curt Hill

Compound statements Either the then statement or the else statement may be replaced with a compound statement In any combination Even the compound statement of an if may create local variables Their scope is confined to the compound statement Copyright © 2004-2012 Curt Hill

Example Revisited Let’s redo the quadratic formula program Copyright © 2004-2012 Curt Hill