Re: Equivalent to Python's range
Posted: Thu Feb 14, 2008 11:36 pm
I think I would prefer the compiler to DWIM and handle this mathematically instead of my having to remember to handle both cases.
Discussion about the Cobra programming language.
http://cobra-language.com/forums/
# slicing is left inclusive, right exclusive:
list = list[0:list.count] # same list
list = list[0:2] # gets 2 elements, not 3
# since for loop generates indexes with same semantics, reuse colons:
for i = 0 : list.count : 2
pass
for i = 0 : list.count ++ 2
pass
for i = 1 .. 100 by 2
for i = 10 .. 0 by -2
for i = 0 : list.count : 2
pass
for i = a : b : +c # goes up
for i = a : b : -c # goes down
# slicing is left inclusive, right exclusive:
list = list[0:list.count] # same list
list = list[0:2] # gets 2 elements, not 3
# since for loop generates indexes with same semantics, reuse colons:
for i = 0 : list.count : 2
pass
for i = 1 : 100
for i = 1 .. 100
for x in 0 : 100
print x
for i in list.count
print i
Chuck wrote:But that's how "for x = 1 .. 100" is implemented in Cobra. It's right exclusive.