From: "Jesús Gabriel y Galán" Date: 2011-05-20T23:45:47+09:00 Subject: Re: Looping n rows in table On Fri, May 20, 2011 at 4:32 PM, Ashok T. wrote: > Hello everyone, > > I am trying to do 'For' loop for the table but i am having a hard time > as it involves iteration. > > Scenario description: > > I have a table where there are 'n' number of rows but fixed number(5) of > columns as shown below. I need to select the dropdown in column 5 if the > text presents in Column 4. > Just to make clear the rows are infinite and can be any no. > > Table name: $b.table(:id, /grid/) > > 1  2  3  4  5 > 2  100  200 > 3 101 201  text  dropdown > 4  102  202 > 5  103  203  text  dropdown > n  104  204 > > > Here's what i come up with. > > i=0 > c=$b.table(:id, /grid/)[i][4] > d=$b.table(:id, /grid/)[i][5] > > > while i<$b.table(:id, /grid/).row.length >   if c.text.exist?==true > $d.select_list.select "dropdown" > else > puts "No value present" > end > end > > it doesn't iterate and gives incorrect results. > > Any help would be appreciated. Some comments, You are using $b, which is a global variable. What is the use case? If you are in the top level (no classes or methods) you don't need that. In order to give better advice we would like to know which kind of object is $b or what is returned by the method $b.table. If it's an array of string arrays, you can do this: table = $b.table(:id, /grid/) table.each do |row| if row[3] == "text" #arrays start at 0 puts row[4] end end Let us know if this works for you, or moves you in the right direction. Jesus.