From: Jeremy McAnally Date: 2007-02-13T00:06:10+09:00 Subject: Re: embedding if statements in upto function.(newbie question) Let's clean your syntax up a little bit first... 0.upto(a.size - 2) do |i| if (a[i][2]==a[i+1][2] and a[i][0]==a[i+1][0]) print ((a[i+1][3] - a[i][3]) / a[i][3] * 100) / n else print 0 end end Looking at this, I (as someone else already stated) would make sure that everything is a number rather than a string. It seems that if you're having problems with the if statement, that's probably the case. I would inspect the objects at every iterations (e.g., rather than just printing 0, I would print a[i][2].inspect and a[i+1][2].inspect or whatever). That should give you some insight as to what's going on. --Jeremy On 2/12/07, Michael Sc wrote: > Thank you to everyone for all of your help. > I was trying to use upto to go through an array of arrays while using if > statments. Could anyone enlighten me on what I am doing wrong with the > if statements? > I am sure it is something easy. > > I tried this: > 0.upto( a.size-2 ) {|i| > if (a[i][2]==a[i+1][2] and a[i][0]==a[i+1][0]) then > print { (a[i+1][3] - a[i][3]) / a[i][3] * 100 } /n > else print 0 > end} > > Thanks again for all of the help. > Michael > > -- > Posted via http://www.ruby-forum.com/. > > -- http://www.jeremymcanally.com/ My free Ruby e-book: http://www.humblelittlerubybook.com/book/ My blogs: http://www.mrneighborly.com/ http://www.rubyinpractice.com/