Using two values for one switch case statement

前端 未结 12 1756
梦谈多话
梦谈多话 2020-11-28 17:56

In my code, the program does something depending on the text entered by the user. My code looks like:

switch (name) {
        case text1: {
            //bla         


        
12条回答
  •  失恋的感觉
    2020-11-28 18:26

    The case values are just codeless "goto" points that can share the same entry point:

    case text1:
    case text4: {
    //Do something
    break;
    }

    Note that the braces are redundant.

提交回复
热议问题