开关语句和号码的范围 [英] Switch statements and ranges of numbers

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

问题描述

你如何制作一个switch语句在AS3的情况下作出适用于数字的整个范围是多少?

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.

推荐答案

您可以使用一个开关块:

You can use a switch block :

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天全站免登陆