Silverfrost Forums

Welcome to our forums

If statement for multiples of an integer

10 Apr 2007 11:08 #1852

Hi

I was hoping someone could offer some advice with the following problem.

I have a loop which executes 8000 times and each time it does, it performs a necessary calculation. However I would like it to print something during the first execution and then at intervals of 32 executions thereafter. In other words, it must print when i=1, 33, 65, 97 etc. The obvious way to do this would be to include an if statement, instructing it to print in the event of 'i' in the DO loop being equal to the specified numbers.

This seems very clumsy so I thought it would be better to instruct it to print at i=1 and every time i-1 is a multiple of 32. -Something like the following:

if (i==1 .OR. REAL(i-1)/REAL(32) = [an integer] )

While the above is clearly incorrect, is there a way of going about the problem in this fashion or a similarly economical one?

Thanks in advance,

Mikhail

10 Apr 2007 2:33 #1853

For integer i, the condition you want is

if(MOD(i,32)==1) print ....

10 Apr 2007 3:28 #1854

Thank you both very much.

Please login to reply.