Printing certain values from a DO loop in Fortran

Click For Summary

Discussion Overview

The discussion revolves around how to print specific values from a DO loop in Fortran, specifically targeting every 100th value of the loop index.

Discussion Character

  • Technical explanation

Main Points Raised

  • One participant describes a Fortran DO loop structure and expresses a desire to print every 100th value of the loop index.
  • Another participant suggests using the modulus operator to determine when to print, proposing the condition "if (mod(i,100) .eq. 0) then" for printing values.
  • A subsequent reply questions whether the proposed solution would only print when i equals 100, noting that for i equal to 200, the condition would not hold true.
  • A later response asserts that the suggested solution works, indicating satisfaction with the proposed method.

Areas of Agreement / Disagreement

Contextual Notes

There may be assumptions about the understanding of the modulus operation and its application in the context of the loop that are not explicitly stated.

Who May Find This Useful

Readers interested in Fortran programming, particularly those looking to manage output within loops, may find this discussion relevant.

johnwalton84
Messages
16
Reaction score
0
I've written a program in Fortran which has a do loop of the form

do i=0,20000

(operations)

end do


I want the program to print the values of the do loop, but only want it to print every 100th value of i (i.e. 100,200,300,400...20000), can anyone suggest a way to do this?
 
Computer science news on Phys.org
if (mod(i,100) .eq. 0) then
print stuff
endif
 
Would that not only work for i=100 though? If i is 200 then the mod(200,100) wouldn't be 0 so it wouldn't print?
 
Obviously not cos its worked :smile:

Thanks for that imabug!
 

Similar threads

Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 7 ·
Replies
7
Views
6K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K