开关语句和数字范围

编程入门 行业动态 更新时间:2024-10-27 01:20:43
本文介绍了开关语句和数字范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在 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

更多推荐

开关语句和数字范围

本文发布于:2023-10-17 13:22:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1501047.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   数字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!