In groovy I can write
def n = 10
print 1..<n
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]
Are there other language that allow to specify range with conditions?
examples
def n = 10
print 1<=..n
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def n = -2
print 1<=..n
Output: [1]
def n = -开发者_运维问答2
print 1..n
Output: [1, 0, -1, -2]
Python has the range()
method which does a similar thing. While it does not use operators for the condition you can specify a start value, stop value and step value. It then creates a list containing all values starting with the start value, then start+step, ... until it reaches the end value (which is not included).
精彩评论