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

前端 未结 7 1118
梦毁少年i
梦毁少年i 2021-02-09 16:07

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

7条回答
  •  长情又很酷
    2021-02-09 16:32

    You can't use conditional statements with switch.

    But you CAN do it with if statements! If you have a loop you can use continue to stop any upcoming lines and start from the beginning of the innermost loop.

    if(age>76){
        // Code...
        continue;
    }else if(age>50){
        // More Code...
        continue;
    }else{
        // Even more code...
        continue;
    }
    

提交回复
热议问题