(while) nested loop

i’m new to programming and this language so i don’t know what im doing wrong, when i run the code its perfectly fine but it freeze at printing stage, i think its related to while nested loop

program task1
implicit none

! declaring variables
real :: dt,tau,t,N,rms,S,tmax,d,Nan
integer :: counter,i,pw,num,mn

open(unit=11,file="tres.txt")

print *, ("Write n!:")
read(*,*) num

!parameters
dt=0.1e0 !time step
tau=5.0e0 !time constant
tmax=tmax*1.0e0
pw=-1 !power
mn=5 !multiplied number

!values
t=0.0e0
N=1000.0e0 !numerical N
i=0

do while(i <= num)

 !dt=(dt**pw)*mn
 S=0.0d0
 counter=0
 do while (t <= tmax)
  counter=counter+1
  t=t+dt
  N=N+(-N/tau)*dt
  Nan=1000.0d0*exp(-t/tau)
  d=N-Nan
  S=S+d**2
 end do
 t=t*0.0e0

 rms=sqrt( S/counter)

 print *, dt,rms
 if (mn==5) then
  mn=mn/5
 else
  mn=mn*5
  pw=pw-1
 end if
 
 i=i+1
end do
 

close(11)

end program task1
1 Like

You have not initialized tmax before you assign tmax*1.0e0 to it.

1 Like

Thank you