ITP 165x Lecture 4: More Conditionals_ Nested Conditionals_ Switch Statements

49 views1 pages

Document Summary

Itp 165: intro to c++ - lecture 4: more conditionals; nested conditionals; switch. Else if must always occur immediately after an if or an else if. An else if does not necessarily need to be followed by an else. You can have any number of else ifs in succession. If you have an else, it must be after all of the else ifs. Only one of the statements will execute. Since an if statement is a type of statement, we can nest them. In many cases, nested ifs can be equivalent to if-else if-else chains. Default case - what"s executed if the variable was not equal to any of the other cases. Switch only works in the instance where the condition is that the value equals a specific number. If you need complex behavior like greater than 0 but less than 100 you need to use if/else if statements. Don"t forget the break after every case.

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