From: Michael Libby Date: 2008-08-06T05:15:12+09:00 Subject: Re: While loop with fixnum - not working On Tue, Aug 5, 2008 at 1:38 PM, Mmcolli00 Mom wrote: > 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 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