CIS 1057 Chapter Notes - Chapter 6: Switch Statement, Logical Connective

28 views3 pages

Document Summary

A nested if statement is an if statement inside of another if statement. Allows us to code decisions with multiple alternatives. Multiple-alternative decisions use an else if to add extra conditions and therefore extra choices. Easier to write and read than if statements with many nested layers. Syntax if (condition1) { statement1; } else if (condition2) { statement2; } else { statement3; } Conditions of the highest restrictions should be placed highest. Nested if statements with more than one variable. If the condition is checking multiple variables, a multiple-alternative decision cannot always be used. The switch statement can be used to select one of several alternatives. Not useful for ranges, but useful for selection based on a single variable value or a simple expression (controlling expression) Syntax switch (controlling expression) { label set statements. Cases may only be integers and characters. Comparison of nested if statements and the switch statement.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents