# While loop with fixnum - not working

**URL:** <https://www.ruby-forum.com/t/while-loop-with-fixnum-not-working/145082>\
**Category:** Ruby\
**Created:** [August 5, 2008, 8:40pm UTC](https://www.ruby-forum.com/t/while-loop-with-fixnum-not-working/145082 "2008-08-05T20:40:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmcolli00](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@mmcolli00](https://www.ruby-forum.com/u/mmcolli00)\
**Post date:** [August 5, 2008, 8:40pm UTC](https://www.ruby-forum.com/t/while-loop-with-fixnum-not-working/145082/1 "2008-08-05T20:40:18Z")

</div>

I can’t get the while loop to work. When I set ErrorCount.Class it  
outputs Fixnum. Do you think that this is the reason that that the while  
will not execute? Thanks in advance. Mom Mcolli00

it (“Search for FieldId Tag containing error in XML file”) do  
ErrFieldID= get\_xml\_attrib\_value(ie, “Error”,“FieldID”)

ErrorCount = ErrFieldID.size #this lets me know what size the array  
is  
puts ErrorCount.class #this shows that it is a Fixnum  
ErrorCount.to\_int #this does nothing  
puts “Total Claim Errors”  
puts ErrorCount #shows correct count!  
end

#this while structure will not work

While ErrorCount \> 0  
ErrFieldID = get\_xml\_attrib\_value(ie,“Error”,“FieldID”)  
code to correct error  
End

---

<div class="post-metadata">

**Author:** ![mmcolli00](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@mmcolli00](https://www.ruby-forum.com/u/mmcolli00)\
**Post date:** [August 5, 2008, 9:51pm UTC](https://www.ruby-forum.com/t/while-loop-with-fixnum-not-working/145082/2 "2008-08-05T21:51:55Z")

</div>

On 5 Aug 2008, at 19:38, Mmcolli00 Mom wrote:

> I can’t get the while loop to work. When I set ErrorCount.Class it  
> outputs Fixnum. Do you think that this is the reason that that the  
> while

Fixnum is a subclass of Integer. For performance reasons, small  
integers will be an instance of Fixnum. This is normal. (not terribly  
relevant here, but it doesn’t really mater what ErrorCount is as long  
as it has a \< method which will accept 0 as an argument)

> ErrorCount.to\_int #this does nothing  
> puts “Total Claim Errors”  
> puts ErrorCount #shows correct count!  
> end
> 
> #this while structure will not work

In what way is it not working ? (assuming the problem is not just that  
while and end should be lowercase)  
Also in ruby a leading capital letter indicates a constant, so you’ll  
probably get errors about “already initialized constant Foo” with code  
like this

Fred

---

<div class="post-metadata">

**Author:** ![mmcolli00](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@mmcolli00](https://www.ruby-forum.com/u/mmcolli00)\
**Post date:** [August 5, 2008, 10:17pm UTC](https://www.ruby-forum.com/t/while-loop-with-fixnum-not-working/145082/3 "2008-08-05T22:17:24Z")

</div>

On Tue, Aug 5, 2008 at 1:38 PM, Mmcolli00 Mom [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> #this while structure will not work
> 
> While ErrorCount \> 0  
> ErrFieldID = get\_xml\_attrib\_value(ie,“Error”,“FieldID”)  
> code to correct error  
> End

Not sure what you mean by “will not work”. If you state your  
expectation and the result you actually got it will help identify what  
went wrong.

If all of the code in your message is one long script, then the  
ErrorCount variable you declared inside the first block (it… do…  
end) has gone out of scope when the while statement is executed. Your  
“while ErrorCount \> 0” is really saying “while nil \> 0” – in other  
words, the condition is always false.

If you have an array (like ErrFieldID) and you want to handle each  
element in it, you probably want to iterate over the array like so:

err\_field\_id = get\_xml\_attrib\_value(ie, “Error”, “FieldID”)  
puts “Total claim errors #{err\_field\_id.size}”  
err\_field\_id.each do |efid|  
puts “Correcting error: #{efid}”  
code\_to\_correct\_error(efid)  
end

-Michael

---

<div class="post-metadata">

**Author:** ![mmcolli00](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@mmcolli00](https://www.ruby-forum.com/u/mmcolli00)\
**Post date:** [August 6, 2008, 10:07am UTC](https://www.ruby-forum.com/t/while-loop-with-fixnum-not-working/145082/4 "2008-08-06T10:07:04Z")

</div>

Michael L. wrote:

> “while nil \> 0” – in other  
> words, the condition is always false.

Actually it’s always a NoMethodError as nil doesn’t have a \> method.

---

<div class="post-metadata">

**Author:** ![mmcolli00](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@mmcolli00](https://www.ruby-forum.com/u/mmcolli00)\
**Post date:** [August 6, 2008, 2:33pm UTC](https://www.ruby-forum.com/t/while-loop-with-fixnum-not-working/145082/5 "2008-08-06T14:33:10Z")

</div>

On Wed, Aug 6, 2008 at 3:04 AM, Sebastian H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Michael L. wrote:
> 
> > “while nil \> 0” – in other  
> > words, the condition is always false.
> 
> Actually it’s always a NoMethodError as nil doesn’t have a \> method.

Thanks for the correction.

-Michael
