Page 1 of 1

Do i in x,y,z

Posted: July 10th, 2018, 7:59 pm
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

Re: Do i in x,y,z

Posted: July 10th, 2018, 10:56 pm
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;

Re: Do i in x,y,z

Posted: July 12th, 2018, 8:12 am
by AriSilva
Thanks,