From: Brian Candler Date: 2007-02-12T22:53:44+09:00 Subject: Re: embedding if statements in upto function.(newbie question) > With this I get an error on the 3rd line of undefined method(-) for ".08 > #(the first number)#":String(NoMethodError)Print was able to do the > calculation without the if statements. I expect the problem is that a[x][y] contains a string, not an integer. You can confirm this by adding puts a.inspect into your program just after you've read in the array, and look for ["0", "1", "2"] instead of [0, 1, 2] To fix the problem, try adding some .to_i calls on the elements before performing the arithmetic on them. irb(main):001:0> a = "9" => "9" irb(main):002:0> b = "6" => "6" irb(main):003:0> a - b NoMethodError: undefined method -' for "9":String from (irb):3 irb(main):004:0> a.to_i - b.to_i => 3 Notice that the problem you have come across has nothing to with "if" statements, nor with them being embedded in the "upto" construct. The moral: try to avoid premature diagnosis :-) Regards, Brian.