











































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to flow control in c++ programming, focusing on if-then-else statements, boolean data type, and control structures. It covers topics such as sequential execution, selection control structures, and loop control structures. The document also explains the use of logical expressions, relational operators, and short-circuiting in c++.
Typology: Slides
1 / 83
This page cannot be seen from the preview
Don't miss anything!












































































bool hasFever; // true if has high temperature
bool isSenior; // true if age is at least 55
temperature > humidity rain >= average B * B - 4.0 * A * C < 0. hours <= 40 abs (number) == 35 initial != ‘Q’
character set values
string myState;
string yourState;
myState = “Texas”;
yourState = “Maryland”;
Expression Value
myState == yourState false
myState > yourState true myState == “Texas” true myState < “texas” true
Logical
Expression Meaning Description
! p NOT p! p is false if p is true ! p is true if p is false
p && q p AND q p && q is true if both p and q are true. It is false otherwise.
p || q p OR q p || q is true if either p or q or both are true. It is false otherwise.
int age; bool isSenior, hasFever; float temperature;
age = 20; temperature = 102.0; isSenior = (age >= 55); // isSenior is false hasFever = (temperature > 98.6); // hasFever is true
Expression Value isSenior && hasFever false isSenior || hasFever true ! isSenior true ! hasFever false
int age, height;
age = 25;
height = 70;
Expression
(age > 50) && (height > 60)
false
Evaluation can stop now because result of && is only true when both sides are true; thus it is already determined that the expression will be false
What happens?
int age, weight;
age = 25;
weight = 145;
Expression
(weight < 180) && (age >= 20)
true Must still be evaluated because truth value of entire expression is not yet known (Why?)
What happens?
int age, height;
age = 25;
height = 70;
Expression
! (height > 60) || (age > 50)
true
false Does this part need to be evaluated?