B
Brian Schroeder
Hello everybody,
I've got a stylistic question. I know that "the ruby way" to implement
iterations is using .each and similar things, but sometimes I like to use
for i in 0...n
for j in i...n
do something with i and for
end
end
Thats nice.
But if I want to iterate downwards the only way I found is 10.downto(0) do
| i | end
That seems not as intuitive as the for notation. Especially if I want ruby
to teach algorithms to people who know how to read pseudo code, then I'd
like something like
I think this has been discussed before, but I'd like to now which style
you use, or if I've missed the solution.
regards,
Brian
PS: How is for implemented? Can I maybe teach Number.downto to return an
object that
is used by for to iterate like an inverse range?
I've got a stylistic question. I know that "the ruby way" to implement
iterations is using .each and similar things, but sometimes I like to use
for i in 0...n
for j in i...n
do something with i and for
end
end
Thats nice.
But if I want to iterate downwards the only way I found is 10.downto(0) do
| i | end
That seems not as intuitive as the for notation. Especially if I want ruby
to teach algorithms to people who know how to read pseudo code, then I'd
like something like
for i in 10.downto 0
for i in 0.upto 10
I think this has been discussed before, but I'd like to now which style
you use, or if I've missed the solution.
regards,
Brian
PS: How is for implemented? Can I maybe teach Number.downto to return an
object that
is used by for to iterate like an inverse range?