Register to reply 
Modifying iteration of DOloop dynamically 
Share this thread: 
#1
Jan2311, 12:53 AM

P: 5

I would like to change the start integer for a DOloop each time the DO runs as a result of the calculations of the previous iteration. For example the first time the DO runs it should start at 1, the second time at 33, the third time at 60. The numerical value for the end of the loop stays the same. I have tried to change the iterator dynamically as can be seen in the code below, but the g77 gives an error.
ACS = 1 NUME = 0 DO 12, AC = ACS,NH IF (VI(AC) .NE. 100.0) THEN VF(AC) = VI(AC) GOTO 12 ELSEIF (VI(AC) .EQ. 100.0) THEN DO 80,AB = AC,AC+24 IF (VI(AB) .EQ. 100) NUME = NUME + 1 IF (VI(AB) .NE. 100) GOTO 81 80 CONTINUE 81 IF ((VI(AC1) VI(AC+NUME)) .GT. 0.0) THEN DO 77, VAL = AC,AC+NUME+1 VF(VAL)=VI(AC)((VI(AC1)VI(AC+NUME))/(NUME+1)) 77 CONTINUE ELSEIF ((VI(AC1) VI(AC+NUME)) .LT. 0.0) THEN NUM = 0 DO 99, VAL = AC,AC+NUME1 NUM = NUM + 1 VF(VAL)=VF(AC+NUM2)+((VI(AC+NUME)VI(AC1))/(NUME+1)) AC = VAL 1 <=== compiler error 99 CONTINUE How can I modify AC without getting a compiler error or is an alernative logic necessary?? 


#2
Jan2311, 01:02 AM

P: 1,781

You cannot do it with a do loop. You must construct one out of goto and if statements. You are then free to modify the dummy variable any way you like.



#3
Jan2311, 07:27 AM

Mentor
P: 11,868

Or use a DO WHILE loop. The following two loops are equivalent:



Register to reply 
Related Discussions  
Riding a Loop the Loop (velocity at the bottom of the loop)  Introductory Physics Homework  13  
Special relativity  dynamically impossible process of a photon to electron+positron  Advanced Physics Homework  1  
Dynamically tuned gyro(DTG)  Mechanical Engineering  1  
Does the PA show that DM/DE is dynamically important in the outer solar system?  Astronomy & Astrophysics  18  
Dynamically Triangulating Gravity hepth/0105267  Beyond the Standard Model  3 