Do i in x,y,z

What would you like to see in CSPro?
Forum rules
New release: CSPro 8.0
Post Reply
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

Do i in x,y,z

Post by AriSilva »

Maybe i´m asking too much, but...
I need to loop through a very large table and execute something just for certain elements.
For example, instead of writing:
do i = 1 until i > 100000
if not i in 1, 570, 800, 900, 1050, 48560, 94980 then //a list of indexes
next; //skip the ones I do not want to process
endif;

//do something for the ones I want to process
mat(i) = 3; //for example
enddo;

I would write:
do i in 1, 570, 800, 900, 1050, 48560, 94980
//do something for the ones I want to process
mat(i) = 3; //for example
enddo;

Besides being much faster because it would not look through the whole table filtering the ones to process, it would be much "cleaner" also.
Best
Ari
Best
Ari
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Do i in x,y,z

Post by Gregory Martin »

You could put those values in an array. Something like:
PROC GLOBAL

numeric NumberValues = 7;
array Values(NumberValues) = 1, 570, 800, 900, 1050, 48560, 94980;

// ...

do numeric ctr = 1 while ctr <= NumberValues

    // do something with Values(ctr)

enddo;
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

Re: Do i in x,y,z

Post by AriSilva »

Thanks,
Best
Ari
Post Reply