多条件案件怎么办? [英] How to do a case with multiple conditions?

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

问题描述

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

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");
}

可悲的是,这种方式似乎并不奏效.我不能在开关盒中进行布尔检查.

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",多个 goto 可以共享同一行来开始执行.

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

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

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