Need help for loop

Hi,
Can anyone please help me. What I want to do here is to print the label
and text field of this part of the table 5 times. The output I expected
to get is this:

TEXT NUMBER 0 (this is where the TEXT_FIELD will appear)
TEXT NUMBER 1 (this is where the TEXT_FIELD will appear)
            .
            .
            .
TEXT NUMBER 5 (this is where the TEXT_FIELD will appear)

This are the codes I used:

<% for num in (0..4) %>
    <tr>
        <td style="width: 374px;"><label>TEXT NUMBER "#{num}"
</label></td>
        <td style="width: 219px;"><input name=""
type="integer"></td>
      </tr>
<% end %>

Thanks,
fries88

Hi,
Can anyone please help me. What I need to do here is to print the label
and text field of this part of the table 5 times. The output I expected
to get is this:

TEXT NUMBER 0 (this is where the TEXT_FIELD will appear)
TEXT NUMBER 1 (this is where the TEXT_FIELD will appear)
             .
             .
             .
TEXT NUMBER 5 (this is where the TEXT_FIELD will appear)

Instead, what I get is:

TEXT NUMBER #{num} (this is where the TEXT_FIELD will appear)
TEXT NUMBER #{num} (this is where the TEXT_FIELD will appear)
             .
             .
             .
TEXT NUMBER #{num} (this is where the TEXT_FIELD will appear)

This are the codes I used:

<% for num in (0..4) %>
     <tr>
         <td style="width: 374px;"><label>TEXT NUMBER "#{num}"
</label></td>
         <td style="width: 219px;"><input name=""
  type="integer"></td>
       </tr>
<% end %>

Thanks,
fries88

Can you loop in Ruby?

Also, you need to use erb to execute the code. I bet you don't
understand what that means.

</annoyingandpro>

August Lilleaas wrote:

Can you loop in Ruby?

Also, you need to use erb to execute the code. I bet you don't
understand what that means.

</annoyingandpro>

On Jan 10, 10:12?am, user splash <rails-mailing-l...@andreas-s.net>

Hi,

Yup I don't understand what your talking about. Can anyone please
explain?

Thanks,
user splash (I am a beginner)

August Lilleaas wrote:

Can you loop in Ruby?

Also, you need to use erb to execute the code. I bet you don't
understand what that means.

</annoyingandpro>

On Jan 10, 10:12?am, user splash <rails-mailing-l...@andreas-s.net>

Hi,

Yup I don't understand what your talking about. Can anyone please
explain?

Thanks,
user splash (I am a beginner)

It's rather confusing if you post with 2 different identities (seems
odd that both you and fries88 have exactly the same question).
Anyway, go back to where you first read about rhtml templates and read
about the difference between <% and <%=
#{} only works when ruby evaluates a string, which isn't what is
happening here.

Fred

Hi um fries 88,

I think the only problem is the TEXT NUMBER "#{num}" line. Where
you've got #{num} here isn't being interpreted by ruby because you've
not wrapped it with an <% %> to tell ruby to take a look at it.
Really you don't need the "#{num}" all you should need to do is TEXT
NUMBER <%= num %>.

Just fyi, using a for loop as you are is a little slower then using
either the times or upto... as far as why it is slower I'm not really
sure, but times and upto are definitely the "ruby way"...

e.g.

<% 5.times do |num| %>
    ... TEXT NUMBER <%= num %> ...
<% end %>

or

<% 0.upto 4 do |num| %>
    ... TEXT NUMBER <%= num %> ...
<% end %>

The upto form has the added benefit that you can start from an
arbitrary place (like 1 if you wanted to be 1 based instead of zero
based) and go through what your ended number should be.

<% 1.upto 5 do |num| %>
   ...
<% end %>

Hope that helps.
-andy:)