forums.silverfrost.com
Welcome to the Silverfrost forums

Author Message
Kalashnikov

Joined: 25 May 2006
Posts: 7

 Posted: Tue Apr 10, 2007 12:08 pm    Post subject: If statement for multiples of an integer 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_________________Mikhail Kalashnikov
brucebowler

Joined: 02 Feb 2006
Posts: 153

 Posted: Tue Apr 10, 2007 2:35 pm    Post subject: temp = real(i-1)/32.0 if (i == 1 .or. int(temp) == temp) Subject of course to the ability to represent certain reals "precisely"... It would work better if you could do temp = real(i)/32.0 if (i == 1 .or. int(temp) == temp) ie 1,32,64,96, etc...
PaulLaidler

Joined: 21 Feb 2005
Posts: 5719
Location: Salford, UK

 Posted: Tue Apr 10, 2007 3:33 pm    Post subject: For integer i, the condition you want is if(MOD(i,32)==1) print ....
Kalashnikov

Joined: 25 May 2006
Posts: 7

 Posted: Tue Apr 10, 2007 4:28 pm    Post subject: Thank you both very much._________________Mikhail Kalashnikov
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 Hour Page 1 of 1