Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

loop for non-integer

Help
Beginner
1,489 Views
Hello,

Can anyone let me know how to loop through non-integers values like from 0.001 to 9.999

Thanks
0 Kudos
8 Replies
Peter
Beginner
1,489 Views
Quoting - Help
Hello,

Can anyone let me know how to loop through non-integers values like from 0.001 to 9.999

Thanks

First of all why do you want to loop a non integer ??

For example, if you want step size of 0.001b/t 1 and 10 ,you may write as follows
[cpp]real(8) i
do i= 1.d0,  10.d0  ,  0.001d0
print*, 'whatever you want'
end do
[/cpp]

Can you be more specific by giving an example what you want to do?
0 Kudos
Steven_L_Intel1
Employee
1,489 Views
Non-integer DO loops are deleted from the standard. Our compiler still supports them, but they're a bad idea, especially as you may be surprised at how many times the loop runs.
0 Kudos
Peter
Beginner
1,489 Views
Non-integer DO loops are deleted from the standard. Our compiler still supports them, but they're a bad idea, especially as you may be surprised at how many times the loop runs.

Steve,

Are you referring to my code ?? If sothere are lot of situations in engineeringproblems that have to loop many times, for example trying to achieve convergence etc.

Ifyou are referring to theoriginal discussion, I did not understand why he/she wants to loop non integer numbers !
0 Kudos
TimP
Honored Contributor III
1,489 Views
Quoting - Peter
[cpp]real(8) i
do i= 1.d0, 10.d0 , 0.001d0
print*, 'whatever you want'
end do
[/cpp]
This was supported in f77 standard, but later deleted from the standard, as e.g.
integer i
do i=1,9999
write(*,*) i*0.001
enddo

has advantages such as an exactly known loop count.
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,489 Views
Quoting - tim18
This was supported in f77 standard, but later deleted from the standard, as e.g.
integer i
do i=1,9999
write(*,*) i*0.001
enddo

has advantages such as an exactly known loop count.

Tim18,

You would want to use "i*0.001D0" or "i*0.001_8" as the original loop code showed use of D variables.

Jim Dempsey
0 Kudos
Help
Beginner
1,489 Views
Quoting - Peter

Steve,

Are you referring to my code ?? If sothere are lot of situations in engineeringproblems that have to loop many times, for example trying to achieve convergence etc.

Ifyou are referring to theoriginal discussion, I did not understand why he/she wants to loop non integer numbers !

Hi Peter,

Thanks for the do loop. It worked for F90.
I wanted to do a small test with non-integer. I have a code where I had to do negative exponential calculations over large values and was never coming out of the loop. So, I had to find the value where it was stuck. This was for the very same purpose (convergence) you have explained.

Thanks again..
0 Kudos
Peter
Beginner
1,489 Views
Quoting - Help

Hi Peter,

Thanks for the do loop. It worked for F90.
I wanted to do a small test with non-integer. I have a code where I had to do negative exponential calculations over large values and was never coming out of the loop. So, I had to find the value where it was stuck. This was for the very same purpose (convergence) you have explained.

Thanks again..
Yeah I kinda figured that you'l be looking for some convergence ! Good luck running your code !
0 Kudos
Help
Beginner
1,489 Views
Quoting - Peter
Yeah I kinda figured that you'l be looking for some convergence ! Good luck running your code !

Thanks Peter...and thanks to everyone who replied to this post
0 Kudos
Reply