Post Reply 
(Recursive) nested loops and IFs?
12-17-2015, 04:17 PM (This post was last modified: 12-17-2015 04:45 PM by Didier Lachieze.)
Post: #5
RE: (Recursive) nested loops and IFs?
Here is a way to replace the nested loops by a single one using a list (LoopIdx) to store the different loop index values. LoopIdx is replacing Loop1, Loop2, Loop3 & Loop4 and allows for a dynamic number of variables as it is sized according to the size of your L3.
This is based on the latest version of your program:

PHP Code:
SUBRFROMTO()
BEGIN
 LOCAL n
IdxLoopIdxs;
 PRINT(); 
 PRINT(
"



                        Completed: 0 %"
);
LoopIdx:=L3;
s:=SIZE(L3);
FOR 
Idx FROM 1 TO ΠLIST(L4-L3) DO
  
TempList:={};
  FOR 
Loop FROM 1 TO SIZE(L2) DO
   
EXPR(L2(Loop)+":=LoopIdx("+STRING(Loop)+ ")");
   
TempList(0):=EXPR(L2(Loop));
  
END;
  
Temp:=0;
  IF 
DigitSum>0 THEN
   
FOR Loop FROM 1 TO SIZE(L5) DO
    
Temp:=Temp+EXPR(L5(Loop));
   
END;
  
END;
  IF (
NOT(DigitSum>0) OR Temp==DigitSum-SubDigitSumTHEN
   
IF ΠLIST(EXECON("EXPR(&1)>=0 AND EXPR(&1)<=9",L5)) THEN
    L8
(0):=""+EXPR(L1(1))+EXPR(L1(2))+"° "+EXPR(L1(3))+EXPR(L1(4))+"."+EXPR(L1(5))+EXPR(L1(6))+EXPR(L1(7));
    
L9(0):=""+EXPR(L1(8))+EXPR(L1(9))+EXPR(L1(10))+"° "+EXPR(L1(11))+EXPR(L1(12))+"."+EXPR(L1(13))+EXPR(L1(14))+EXPR(L1(15));
    
L6(0):=TempList;
    
Dist:=acos(sin(PublLat)*sin(FUNCDMTODEG(L8(0)))+cos(PublLat)*cos(FUNCDMTODEG(L8(0)))*cos(FUNCDMTODEG(L9(0))-PublLon));
    
IFERR(acos((sin(FUNCDMTODEG(L8(0)))-sin(PublLat)*cos(Dist))/(sin(Dist)*cos(PublLat)))) THEN
     L0
(0):=ROUND(6371*π/180*Dist,-3)+" km  error°";
    ELSE
     
θ:=360-acos((sin(FUNCDMTODEG(L8(0)))-sin(PublLat)*cos(Dist))/(sin(Dist)*cos(PublLat)));
     
L0(0):=ROUND(6371*π/180*Dist,-3)+" km  "+ROUND(θ,0)+"°";
    
END;
   
END;
  
END;

  
//increment LoopIdx
  
LoopIdx(s):=LoopIdx(s)+1;
  FOR 
n FROM s DOWNTO 1 DO
    IF 
LoopIdx(n)>L4(nTHEN
      LoopIdx
(n):=L3(n);
      
LoopIdx(n-1):= LoopIdx(n-1)+1;
      IF 
n==2 THEN
       
PRINT(); 
       PRINT(
"



                              Completed: "
+ROUND(100*(1+LoopIdx(1)-L3(1))/(1+L4(1)-L3(1)),0)+" %");
      
END;
    
END;
  
END;
END;
END

It is working with the test case you provided.
I'm not a geocacher but I know some people who are and may be interested by your program.

Here are the detailed modifications I've made to your program:
  • added some local variables : n, Idx, LoopIdx, s
  • initialized LoopIdx to L3 : list of the start values, and s to the size of L3
  • replaced the nested FOR loops by a single one from 1 to the total of loops to be done: product of differences between upper and lower values in L4 and L3
  • modified the expression in the first loop to replace Loopi by LoopIdx(i)
  • added the increment of the LoopIdx values at the end of the FOR loop, including the progress PRINT instruction
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (Recursive) nested loops and IFs? - Didier Lachieze - 12-17-2015 04:17 PM



User(s) browsing this thread: 1 Guest(s)