110 likes | 221 Views
INFSY 307 C++. Flow of Control. Flow of Control: order in which statements are performed. Sequence: one after the other Selection: selects a path based upon action Iteration: repetition. CONTROL STRUCTURES. Sequence.
E N D
INFSY 307 C++ Flow of Control
Sequence: one after the other • Selection: selects a path • based upon action • Iteration: repetition CONTROL STRUCTURES
Sequence • One immediately following the other • Ordered flow of program logic • All programs follow this order unless directed to proceed in another manner
Selection(Branching alters flow of control) If (logical expression) { statement(s); }
Selection (Continued) If (logical expression) { statement(s); } else { statement; }
Selection Example If (hours <= 40.0) { pay = rate * hours; } else { pay = rate * (40.0 + (hours - 40.0) * 1.5); } cout<<pay; //assume all types are float
Selection • Only one of the two branches is executed • If the comparison is true, the first statement(s) are executed • If the comparison is false, the second statement(s) are executed
Let’s Try • Page 79 Savitch • #17 • #18