Programming Logic and Design Sixth Edition
Programming Logic and Design Sixth Edition
Programming Logic and Design Sixth Edition
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Underst<strong>and</strong>ing the Three Basic<br />
Structures (continued)<br />
Underst<strong>and</strong>ing the Three Basic<br />
Structures (continued)<br />
• Dual-alternative if<br />
– Contains two alternatives<br />
– If-then-else structure<br />
if someCondition is true then<br />
else<br />
do oneProcess<br />
do theOtherProcess<br />
Figure 3-3 Selection structure<br />
<strong>Programming</strong> <strong>Logic</strong> & <strong>Design</strong>, <strong>Sixth</strong> <strong>Edition</strong> 7<br />
<strong>Programming</strong> <strong>Logic</strong> & <strong>Design</strong>, <strong>Sixth</strong> <strong>Edition</strong> 8<br />
Underst<strong>and</strong>ing the Three Basic<br />
Structures (continued)<br />
Underst<strong>and</strong>ing the Three Basic<br />
Structures (continued)<br />
• Single-alternative if<br />
if employee belongs to dentalPlan then<br />
deduct $40 from employeeGrossPay<br />
– Else clause is not required<br />
• null case<br />
– Situation where nothing is done<br />
Figure 3-4 Single-alternative selection structure<br />
<strong>Programming</strong> <strong>Logic</strong> & <strong>Design</strong>, <strong>Sixth</strong> <strong>Edition</strong> 9<br />
<strong>Programming</strong> <strong>Logic</strong> & <strong>Design</strong>, <strong>Sixth</strong> <strong>Edition</strong> 10<br />
Underst<strong>and</strong>ing the Three Basic<br />
Structures (continued)<br />
• Loop structure<br />
– Repeats a set of actions based on the answer to a<br />
question<br />
• Loop body<br />
– Also called repetition or iteration<br />
– Question is asked first in the most common form of<br />
loop<br />
– while … do or while loop<br />
Underst<strong>and</strong>ing the Three Basic<br />
Structures (continued)<br />
Figure 3-5 Loop structure<br />
<strong>Programming</strong> <strong>Logic</strong> & <strong>Design</strong>, <strong>Sixth</strong> <strong>Edition</strong> 11<br />
<strong>Programming</strong> <strong>Logic</strong> & <strong>Design</strong>, <strong>Sixth</strong> <strong>Edition</strong> 12<br />
2