# Error in Loop!

**URL:** <https://rubytalk.org/t/error-in-loop/41107>\
**Category:** ruby-talk\
**Created:** [2 October 2007 13:40 UTC](https://rubytalk.org/t/error-in-loop/41107 "2007-10-02T13:40:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Nott](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@John\_Nott](https://rubytalk.org/u/John_Nott)\
**Post date:** [2 October 2007 13:40 UTC](https://rubytalk.org/t/error-in-loop/41107/1 "2007-10-02T13:40:40Z")

</div>

Hi Everyone!  
I keep getting the following error message for this line of the below code:

mat1[r,c] \<\< this\_record.chomp(",").strip()

I have been racking my brain but can't see a sollution - have used this line before so pretty baffled!!  
Anyone got any ideas - would be very appreciated!  
The error message is:

&nbsp;&nbsp;&nbsp;&nbsp;Error: private method `\<\<' called for 0.0:Float  
&nbsp;&nbsp;&nbsp;  
HERE IS THE FULL CODE

mat1 = OtMatrix.new(19,649)

r = 0  
c = 1

while ( !file.eof )  
line = file.gets  
r = r+1  
line.each(',') { |this\_record|  
&nbsp;&nbsp;mat1[r,c] \<\< this\_record.chomp(",").strip()  
&nbsp;&nbsp;c = c+1  
if c == 19 then  
c == 1  
end  
&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
end

> **···**
>
> #####################################################################################  
> This e-mail message has been scanned for Viruses and Content and cleared  
> by MailMarshal  
> #####################################################################################

---

<div class="post-metadata">

**Author:** ![7stud1](https://avatars.discourse-cdn.com/v4/letter/7/59ef9b/32.png) [@7stud1](https://rubytalk.org/u/7stud1)\
**Post date:** [2 October 2007 13:50 UTC](https://rubytalk.org/t/error-in-loop/41107/2 "2007-10-02T13:50:55Z")

</div>

0.0 \<\< "hello world"

--output:--  
r6test.rb:1: undefined method `\<\<' for 0.0:Float (NoMethodError)

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Forum](https://avatars.discourse-cdn.com/v4/letter/f/43a26b/32.png) [@Forum](https://rubytalk.org/u/Forum)\
**Post date:** [2 October 2007 13:51 UTC](https://rubytalk.org/t/error-in-loop/41107/3 "2007-10-02T13:51:31Z")

</div>

You try to append the RHS to a float, which is what  
mat1[r,c] evaluates to, that does not work of course.

It is difficult to fix the error because I do not know what you want to achieve  
depending on the API of OtMatrix maybe the following would make sense

mat1[r] \<\< RHS # adding an element to a row, however now you might  
have an irregular matrix  
mat1 \<\< RHS # adding a new line at the end of the Matrix, is this what you want?

HTH  
Robert

> **···**
>
> On 10/2/07, John Nott \<JNott@dto.ie\> wrote:
> 
> > Hi Everyone!  
> > I keep getting the following error message for this line of the below code:
> > 
> > mat1[r,c] \<\< this\_record.chomp(",").strip()
> 
> --  
> what do I think about Ruby?  
> [http://ruby-smalltalk.blogspot.com/](http://ruby-smalltalk.blogspot.com/)

---

<div class="post-metadata">

**Author:** ![7stud1](https://avatars.discourse-cdn.com/v4/letter/7/59ef9b/32.png) [@7stud1](https://rubytalk.org/u/7stud1)\
**Post date:** [2 October 2007 13:54 UTC](https://rubytalk.org/t/error-in-loop/41107/4 "2007-10-02T13:54:39Z")

</div>

John Nott wrote:

> &nbsp;&nbsp;mat1[r,c] \<\< this\_record.chomp(",").strip()

Is there an \<\< operator defined for that class? Are you sure it  
shouldn't be:

mat1[r,c] = this\_record.chomp(",").strip(0

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![7stud1](https://avatars.discourse-cdn.com/v4/letter/7/59ef9b/32.png) [@7stud1](https://rubytalk.org/u/7stud1)\
**Post date:** [2 October 2007 13:52 UTC](https://rubytalk.org/t/error-in-loop/41107/5 "2007-10-02T13:52:33Z")

</div>

7stud -- wrote:

> 0.0 \<\< "hello world"
> 
> --output:--  
> r6test.rb:1: undefined method `\<\<' for 0.0:Float (NoMethodError)

Whoops. Not the same error.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
