Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop over numbered variables

Status
Not open for further replies.

zapal

Technical User
Oct 23, 2008
3
GB
Hello, I have following problem. I have integer variables, say a1, a2 and a3 and want a do ... loop running over i=1,3 to do something for each of those a's, say print them for simplicity. More specifically, I would write

integer :: a1,a2,a3
[assign integers to a's]

do i=1,3
[print a's]
end do

How do I do the [print a's] part?

I know I can put a's into an array and then iterate over position index of that array, but is there a more direct way?

Thank you
Jan
 
What's the point? If you make an array of your a's, as you propose yourself, you already have the most direct way.

It seems to me that you're complicating it more by declaring scalar integers.

 
Hello

You might be right, good point ... but is it in principle doable? Say I am working with a's somewhere else in the program and there, I need them to be scalars ... I know I can always type a(1,1) though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top