I want to use a switch statement, and my condition fot the if is:
if (userInput%2 == 0 || userInput != 0)
Can I get two cases from this code to execute different actions for userInput == 0 and different one for userInput == 0
case ?:
case ?:
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You cannot, because the value sets satisfying the two conditions overlap. Specifically, all even numbers satisfy both parts of your conditions. That is why you cannot perform different actions without deciding first which part of the condition takes precedence.
You can play a little trick with fall-through inside the
switchstatement, like this: