## modifying the order of the loops

## modifying the order of the loops

(OP)

Hi guys! I am trying to modify my code but it do not works.

I am trying to put "DO j= 1, 1000" first that "DO i= 1, 20". How to do and keep the same results?

DO i = 1, 20

m = 0

m_2 = 0

p = 10*i

DO j = 1, 1000

d = 0

c = 0

DO

IF (harvest .lt. 0.5) THEN

d = d + 1

ELSE

d = d - 1

END IF

c = c + 1

IF (c .eq. p) exit

END IF

END DO

m = m + d/real(1000)

m_2 = m_2 + (d**2)/real(1000)

END DO

WRITE(1, *) p, m

dp = sqrt(m_2 - m**2)

WRITE(2, *) p, dp

WRITE(3, *) sqrt(REAL(p)), log(dp)

END DO

I am trying to put "DO j= 1, 1000" first that "DO i= 1, 20". How to do and keep the same results?

DO i = 1, 20

m = 0

m_2 = 0

p = 10*i

DO j = 1, 1000

d = 0

c = 0

DO

IF (harvest .lt. 0.5) THEN

d = d + 1

ELSE

d = d - 1

END IF

c = c + 1

IF (c .eq. p) exit

END IF

END DO

m = m + d/real(1000)

m_2 = m_2 + (d**2)/real(1000)

END DO

WRITE(1, *) p, m

dp = sqrt(m_2 - m**2)

WRITE(2, *) p, dp

WRITE(3, *) sqrt(REAL(p)), log(dp)

END DO

## RE: modifying the order of the loops

Now, given that p has a maximum of 10*20 = 200, there is no need for the inner loop to be larger than 200.

## RE: modifying the order of the loops

now I have : "1000*(10 + 200)*20/2" and I want: "1000*20*10" which looks lik possible.