Hi, I have loops that loop through params values from a form and retrieve records from the database and then plot a graph. BUT: If the user selects a check box in the form the loop is 3 nested loops instead of 5. ALSO: There is another checkbox that causes 5 loops (same as first case) but does an extra calculation on the records in the inner loop. My point is these 3 cases are similar: how should I deal with them? At the moment the loops all occur in the controller - should I move them to a model - a model for each graph type? Or should I have one set of loops and do some clever conditional flow to get all three cases out of it? Any ideas on the best practice when doing loops? Chris.
on 2007-01-30 13:47
on 2007-01-30 13:59
Why on earth do you need 5 nested loops? What are you trying to do?
on 2007-01-30 16:37
Mick Sharpe wrote: > Why on earth do you need 5 nested loops? What are you trying to do? Well, the query to make up the graph requires 5 different parameters - it is to graph measurements made on a machine: there are 10 machines - so the user selects one (or multiple) there are 8 different measurement types there are 2 types of machine output there are 3 types of something else they must select the date range and a check box whether they want the results as % of a reference value or not. I then, for each machine, loop through what is required and get the results from the database on the inner loop. I then loop through it all to send results to gnuplot. It starts to become a head ache. Questions from my first post still stand. Chris.
on 2007-01-30 16:50
You might be able to dry up your code using some code that I knocked up to iterate over a number of arrays using nested looping: http://www.ruby-forum.com/topic/95539
on 2007-01-30 17:00
Mick Sharpe wrote: > You might be able to dry up your code using some code that I knocked up > to iterate over a number of arrays using nested looping: > > http://www.ruby-forum.com/topic/95539 Great Mick, that's a slick bit of code - could be just what I need.
on 2007-01-30 17:42
Chris Finch wrote: > Mick Sharpe wrote: >> You might be able to dry up your code using some code that I knocked up >> to iterate over a number of arrays using nested looping: >> >> http://www.ruby-forum.com/topic/95539 > > Great Mick, that's a slick bit of code - could be just what I need. Darn, I have to do some processing between loops - i.e. not just on the inner loop - don't think I can use it:-( C