如果条件如何写. [英] How to write if condition.

查看:112
本文介绍了如果条件如何写.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我要这样写switch case语句,

I want to write the switch case statement such that ,

对于每种情况,我都会检查情况.例如

for each case i will be checking condition. e.g.

switch(expr)

switch(expr)

案例(如果声明写在这里)

如何实现此功能.

推荐答案

不太确定您要问什么.

Not really sure what you are asking.

switch语句仅允许您基于switch表达式跳转到case部分.见 文档.

A switch statement only allows you to jump to a case section based on the switch expression. See the documentation.

通过使用多个相邻的大小写行,可以使开关表达式的多个值跳转到同一部分:

You can have multiple values of the switch expression jump to the same section by using multiple case lines next to each other:

switch (expr)
{
  case "1":
  case "one":
     // do something if expr = "1" or "one"
     break;
  case "2":
  case "two":
     // do something else if expr = "2" or "two"
     break;
  default:
     // do something by default
     break;
}

当然,否则,您总是可以在'case'子句中使用'if'语句,就像其他任何程序块一样.或者...根本不使用switch语句!如果您只想像这样的逻辑,这可能不是您需要的工具:if(something){...} else if(somethingelse){...} else {...};

Otherwise, of course, you can always have an 'if' statement inside the 'case' clause just like any other program block. Or...just don't use a switch statement at all! This may not be the tool you need if you just want logic like: if (something) {...} else if (somethingelse) {...} else {...};

如果这不能解释您想要的内容,则可能需要解释您试图重现的逻辑.

If this doesn't explain what you want, you may need to explain what logic you are trying to reproduce.



这篇关于如果条件如何写.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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