Break label in switch

后端 未结 3 980
既然无缘
既然无缘 2021-01-19 04:42

Edited: Thank you all for your help. I was able to get it working using the the skills I learned in the previous chapters and your advice. Thank you so much!

3条回答
  •  伪装坚强ぢ
    2021-01-19 04:52

    You can enclose the code in a while loop as follows to achieve the task:

    boolean validChoice=false;
    while(!validChoice){
    switch(choice){
        case 1:
            //logic
            validChoice=true;
        case 2:
            //logic
            validChoice=true;
        case 3:
            //logic
            validChoice=true;
        default:
            //print "invalid choice" and ask to reenter
    
    }
    

提交回复
热议问题