Download presentation
Presentation is loading. Please wait.
1
Conditions and Decisions
2
Assignments Reading – Chapter 4 – 4.5-4.8
3
Conditions score > 90 Evaluates to true (1) or false (0) Generally … variable operator variable variable operator constant
4
Relational Operators < > <= >= == –NOT the same as = !=
5
Examples x=5 y=8 z=5 MAX=10 initial=‘s’ x<y y>MAX x<=z z>=MAX initial==‘r’ x!=z
6
Logical Operators && || x=5 y=8 z=5 MAX=10 initial=‘s’ x MAX
7
Precedence function calls unary operators (! + - &) * / % + - = > == != && || =
8
Short-Circuit Evaluation Stop evaluation when true/false value is determined x=6 y=9 x>2 || y > 13 x 13
9
Logical Assignment and Negation int in_range; //1 if x between 1-10, 0 otherwise in_range = (x>0 && x<=10); int same_initials; int not_same_initials; same_initials = (first_initial==‘S’&& last_initial==‘R’); not_same_initials = ! (first_initial==‘S’&& last_initial==‘R’); not_same_initials = (first_initial!=‘S’ || last_initial!=‘R’);
10
DeMorgan’s Theorem !(a && b) => (!a || !b) !(a || b) => (!a && !b)
11
if Statement if(condition) { statements } if(condition) single statement
12
Example if(age >= 16) printf(“You can legally drive a car.”); if(age >= 21) { printf(“You can purchase alcohol.”); printf(“You can gamble.”); }
13
if/else Statement if(condition) { statements } else { statements } if(condition) single statement else single statement
14
Example if(grade > 60) printf(“You pass the class.”); else printf(“You failed, try again.”); if(grade > 60) { printf(“You pass the class.”); printf(“Move on to the next class in the sequence.”); } else { printf(“You failed, try again.”); printf(“You cannot advance to the next class.”); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.