Counter problem for specific file types

N

Ne Scripter

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. So you will end up
with an output like this

control, 0
process, 1
process, 2
process, 3,
control, 0
process, 1
something else, NULL
control, 0
control, 0
process, 1

and so on.

I hope I am making sense with this, remember this code is in a while
loop going through each individual item.

Any input to get started on this is greatly appreciated.
 
J

Jesús Gabriel y Galán

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 =3D=3D "Control"
number =3D "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 =3D "control"
number =3D 0
elsif type =3D "process"
=A0number =3D counter starting at one
end

It will keep adding a continuous =A0number 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 =3D 1
if type =3D=3D "control"
number =3D 0
counter =3D 1
elsif type =3D=3D "process"
number =3D counter
counter +=3D 1
end

Hope this helps,

Jesus.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top