ECS 30 Lecture Notes - Lecture 9: Semicolon, Switch Statement, Control Flow
Document Summary
Else: provides a way to execute the code if the condition is false. Statements should be surrounded by braces {: if blocks are composed of only onestatement, braces can be omitted. Not recommended - can lead to errors: nested if statements. Monday, 16 april 2018: cascading if statements. Conditions are executed until one is satis ed: order matters: else if conditions will be executed only if the the. Rst if condition isn"t, and so on: on the other hand, if you only write if statements (instead of else-if) all conditions will be tested, unlimited number of else ifs, final else not mandatory. Remember: true returns 0: the switch statement. Expression can only be int or char. When the variable being switched on is equal to a case, the statements following that case will execute until a break statement is reached. Not every case needs to contain a break.