From: "Jesús Gabriel y Galán" Date: 2009-09-03T19:44:35+09:00 Subject: Re: Counter problem for specific file types On Thu, Sep 3, 2009 at 11:58 AM, Ne Scripter wrote: > Hi all, > > This is a real teaser for me and would appreciate some help with the > logic. I want to introduce some numbering to a data set. Basically I > have two sets of items the,a control item and a process item. The > control item is always assigned the number 0 eg. if type == "Control" > number = "0" end > > A control item may or may not have process, and may have multiple > processes. I have a while loop that goes through every single item and > when it encounters a Control item it assigns it a 0, what I want it to > do also is assign a continuous number to each process item. > > Take this algorithm > > if type = "control" > number = 0 > elsif type = "process" >  number = counter starting at one > end > > It will keep adding a continuous  number to each process item until it > comes across a type of control or something else. If I understood correctly, what you can do is to have a counter that starts at 1, and it's reset every time you come across a "control" or that "something else you mention": counter = 1 if type == "control" number = 0 counter = 1 elsif type == "process" number = counter counter += 1 end Hope this helps, Jesus.