切换多案陈述 [英] Switch multiple case statement

查看:81
本文介绍了切换多案陈述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以建议我如何替换下面的代码吗?

Can someone suggest me how can I replace the below code?

如何重写代码以避免重复执行case 3:{code block A; break;}块?

How do I rewrite the code in order to avoid the repetition of the block case 3:{code block A; break;}?

switch(i) {
  case 1:  {code block A; break;}

  case 2:  {code block b; break;}

  case 3:  {code block A; break;}

  default: {code block default; break;}
}

如何合并案例1和案例3的代码?

How can I have combined code for case 1 and case 3?

推荐答案

此格式显示在 PHP文档:

switch (i) {
    case 1:
    case 3:
        code block A;
        break;
    case 2:
        code block B;
        break;
    default:
        code block default;
        break;
}

这篇关于切换多案陈述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆