From: Michael Sc Date: 2007-02-13T00:35:41+09:00 Subject: Re: embedding if statements in upto function.(newbie questio thank you very much. I had an issue with the string. I adjusted the code to the following. I knew it had to be something incredibly trivial. Thank you all again. y=0.upto(a.size - 2 ) do |i| if (a[i][2]==a[i+1][2] and a[i][0]==a[i+1][0]) then puts ((a[i+1][3].to_f - a[i][3].to_f) / a[i][3].to_f * 100) else puts 0 end Jeremy McAnally wrote: > 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: >> 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/ -- Posted via http://www.ruby-forum.com/.