fortran 代码 如下
implicit none
real ran,tempran
integer tord
integer ord(60)
logical flag
integer newloop,ii
call init_random_seed()
do newloop=1,50
call random_number(ran)
tempran=50.0*ran
tord=floor(tempran)+1
flag=.true.
do while(flag)
if(newloop==1) then
flag=.false.
end if
flag=.false.
if(newloop/=1) then
do ii=1,newloop-1
if(tord==ord(ii)) then
flag=.true.
exit
end if
end do
end if
end do
ord(newloop)=tord
write(*,*) tord
end do
stop
end
子程序 init_random_seed() 是产生随机数种子的程序
以下是windows下和linux下的结果
这个程序出来的结果是 如果出现ord(i)==ord(z) (z<i)就会出现无限循环,但是在linux下程序却全部运行,即使出现ord(i)==ord(z) (z<i)
请问各位虫友,这是编译器的问题,还是其他什么原因?
在linux下的运行此程序时,只要在 do while 循环中加入一个输出语句
如
do while(flag)
if(newloop==1) then
flag=.false.
end if
flag=.false.
if(newloop/=1) then
do ii=1,newloop-1
if(tord==ord(ii)) then
flag=.true.
write(*,*) tord
exit
end if
end do
end if
end do
这时程序又会执行do while循环,从而出现无限循环的情况。
请好心的虫友,帮忙解答一下,谢谢了。