如何处理多个条件? [英] How to do a case with multiple conditions?

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

问题描述

在我使用任何编程语言的1个月经验中,我假设开关 案例条件将接受括号中的任何内容作为布尔检查thingamajig,即
这些:

In the 1 month experience I've had with any programming language, I've assumed that switch case conditions would accept anything in the parenthesis as a boolean checking thingamajig, ie these:

|| && < >

知道我的意思吗?

某事喜欢

char someChar = 'w';
switch (someChar) {
case ('W' ||'w'):
    System.out.println ("W or w");
}

可悲的是,似乎没有这种方式。我不能在switch case中进行布尔检查。

Sadly, doesn't seem to work that way. I can't have boolean checking in switch case.

有没有办法绕过它?

顺便说一句,如果我听起来很混乱,非常抱歉。我还不太清楚这种语言的所有名称:X

任何答案都赞赏

By the way, terribly sorry if I'm sounding confusing. I don't quite know the names for everything in this language yet :X
Any answers appreciated

推荐答案

对于这样的情况你可以实现OR:

You can achieve an OR for cases like this:

switch (someChsr) {
case 'w':
case 'W':
    // some code for 'w' or 'W'
    break;
case 'x': // etc
}

案例就像一个goto和多个gotos可以共享同一行开始执行。

Cases are like a "goto" and multiple gotos can share the same line to start execution.

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

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