[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ruby-tut] question about an exercise of the chapter 3 (iterators)
From: |
Daniel Carrera |
Subject: |
Re: [ruby-tut] question about an exercise of the chapter 3 (iterators) |
Date: |
Tue, 15 Apr 2003 15:30:01 -0400 |
User-agent: |
Mutt/1.4i |
> I have a small question about this exercise of the chapter 3,
> 'iterators' section:
>
> "Print the lyrics to "99 bottles of beer on the wall" using an
> iterator."
>
> Well, I saw that this exercise was already asked in chapter 2, 'loops'
> section:
>
> "Print out all the lyrics to "99 bottles of beer on the wall."
>
> My question is: "how the reader is expected to resolve the exercise of
> the chapter 2, without using an iterator? (such as Integer#times)?"
Well, the reader *will* be using an iterator, they just won't know that
it is an iterator. They'll just call it a "loop".
The answer is identical to the "counting backwards" section:
count = 99
99.times do
count -= 1
puts count.to_s + " bottles of beer on the wall"
end
In chapter 3 we see iterators, so hopefully they can realize that this can
also be done with:
99.times do |count|
puts count.to_s + " bottles of beer on the wall"
end
That was my thinking.
Perhaps I can refrase the question on chapter 3 to make this more evident.
I'm not sure how... any suggestions?
> PS: i commited gabriel's &IRB; suggestion for the French files.
> I'm now moving the stylesheets to the ``share'' directory, as we
> discussed yesterday.
Great. I liked the &IRB; idea.
Cheers,
--
Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137