开关语句和数字范围 [英] Switch statements and ranges of numbers

查看:34
本文介绍了开关语句和数字范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 as3 中编写 switch 语句,使 case 适用于整个数字范围?

How do you craft a switch statement in as3 to make the case apply to an entire range of numbers?

if (mcPaddle.visible == true)
{
    switch (score)
    {
        case  10://10 to 100
            myColor.color = 0x111111;
            break;
        case 110://110 to 1000
            //etc etc
            break;
    }
}

我尝试了多种方法来使案例适用于 10-100 和 110-1000 之间的所有数字,但似乎找不到方法,而且我找不到正确的语法as3中有这样的事情.

I've tried multiple ways to make the case apply for all numbers between 10-100, and 110-1000, but can't seem to find a way to do it, and I can't find the proper syntax for such a thing in as3.

推荐答案

您可以使用开关块:

var score:Number = 123;

switch(true){

    case score > 120 && score < 125 :
        trace('score > 120 && score < 125');
        break;

    case score > 100 && score < 140 :
        trace('score > 100 && score < 140');
        break;

    case score == 123 :
        trace('score == 123');
        break;

}
//score > 120 && score < 125

这篇关于开关语句和数字范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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