Quantcast
Channel: Can you use conditional statements in switch-case in Android? - Stack Overflow
Viewing all articles
Browse latest Browse all 8

Can you use conditional statements in switch-case in Android?

$
0
0

I can't seem to find a straight forward yes or no to this in my searching. In Android, is there a way to use a conditional statement in case-switch? For example, with age being an int value:

switch (age){case (>79): // Do this stuff break;case (>50): // Do this other stuffbreak;etc, etc

I've tried several ways to code this (completely shooting in the dark) and come up with compiler errors, and I've also tried a nested IF statement, but it doesn't support break so the logic breaks down and it ends up also executing ELSE code lower in the nesting. I feel like switch-case is my best bet but I can't find an example of the correct syntax for what I'm trying to do! Any help would be appreciated. All the examples I find just use switch-case for a few things like if it is a 1 do this, if it's a 2 do that, but without making 100 case statements to check against age, I'm not sure how else to work this.


Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images