Do i in x,y,z

What would you like to see in CSPro?
AriSilva
Posts: 175
Joined: July 22nd, 2016, 3:55 pm

Do i in x,y,z

Postby AriSilva » July 10th, 2018, 7:59 pm

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: 1077
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Do i in x,y,z

Postby Gregory Martin » July 10th, 2018, 10:56 pm

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: 175
Joined: July 22nd, 2016, 3:55 pm

Re: Do i in x,y,z

Postby AriSilva » July 12th, 2018, 8:12 am

Thanks,
Best
Ari


Return to “Feature Requests”