确定变量是否在范围内? [英] Determining if a variable is within range?
本文介绍了确定变量是否在范围内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要编写一个类似于以下内容的循环:
I need to write a loop that does something like:
if i (1..10)
do thing 1
elsif i (11..20)
do thing 2
elsif i (21..30)
do thing 3
etc...
但到目前为止,在语法方面走错了道路。
But so far have gone down the wrong paths in terms of syntax.
推荐答案
if i.between?(1, 10)
do thing 1
elsif i.between?(11,20)
do thing 2
...
这篇关于确定变量是否在范围内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文