Computer Applications
Answer
Two differences between if-else-if and switch-case statements are:
- switch-case statement can only test for equality whereas if-else-if can test for any Boolean expression.
- switch-case tests the same expression against constant values while if-else-if can use different expression involving unrelated variables.
Related Questions
Rewrite the following code using single if statement.
if(code=='g') System.out.println("GREEN"); else if(code=='G') System.out.println("GREEN");Differentiate between if else if and switch-case statements
The statement that brings the control back to the calling method is:
- break
- System.exit(0)
- continue
- return