Selection Structures: Single-alternative Stewart Venit ~ Elizabeth Drake Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. An Introduction to Selection Structures • Single-alternative (If-Then) – A single block of statements to be executed or skipped • Dual-alternative (If-Then-Else) – Two blocks of statements, one of which is to be executed, while the other one is to be skipped • Multiple-alternative (If-Then-Else-If or Case/Switch) – More than two blocks of statements, only one of which is to be executed and the rest skipped 1-2 © 2011 Pearson Addison-Wesley. All rights reserved. 1-2 Single Alternative: General Form 1-3 © 2011 Pearson Addison-Wesley. All rights reserved. 1-3 Single Alternative 1-4 © 2011 Pearson Addison-Wesley. All rights reserved. 1-4 Single Alternative: Example 1-5 © 2011 Pearson Addison-Wesley. All rights reserved. 1-5 Single Alternative If something is true Then Do something (any number of statements) End If Write “How old are you?” Input Age If Age >= 18 Set Eligibility = “Yes” Write “You can vote.” Do other things… End If 1-6 © 2011 Pearson Addison-Wesley. All rights reserved. 1-6 Flowchart for Single Alternative Selection Structures 1-7 © 2011 Pearson Addison-Wesley. All rights reserved. 1-7 Any Questions 1-8 © 2011 Pearson Addison-Wesley. All rights reserved. 8