Post Reply 
(Recursive) nested loops and IFs?
12-17-2015, 08:20 PM (This post was last modified: 12-17-2015 08:25 PM by chromos.)
Post: #6
RE: (Recursive) nested loops and IFs?
Thank you, Didier, you helped me very much.

PHP Code:
IF ΠLIST(EXECON("EXPR(&1)>=0 AND EXPR(&1)<=9",L5)) THEN
  
[...]
END
1) Lines above works perfectly. I tried to understand them, but not much successfuly. ΠLIST is importatnt or it may be ∑LIST too? I know, I could try it myself. :-)

2) Nested loops: I didn't try your code yet, but I will. There is ΠLIST again so I should study its usability much more.

-----
Meanwhile I updated my program again and I replaced nested loops with strings executed via EXPR. Fortunately, code isn't unreadable (I moved lines within FOR-DO and END; into subroutine which helped).

Before:
PHP Code:
FOR Loop1 FROM L3(1TO L4(1) DO
 FOR 
Loop2 FROM L3(2TO L4(2) DO
  FOR 
Loop3 FROM L3(3TO L4(3) DO
   FOR 
Loop4 FROM L3(4TO L4(4) DO
    [...]
   
END;
  
END;
 
END;
 PRINT(); 
 PRINT(
"



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

After (I declared Loop1, ... , Loop20 for sufficient headroom):
PHP Code:
//nested loops preparation
TempFor:="";
TempEnd:="";
TempBody:="";
FOR 
Loop FROM 2 TO SIZE(L2) DO
 
TempFor:=TempFor+"FOR Loop"+STRING(Loop)+" FROM L3("+STRING(Loop)+") TO L4("+STRING(Loop)+") DO ";
 
TempEnd:=TempEnd+"END; ";
END;
TempBody:="SUBRVALIDCOORDS();";
//end of preparation
FOR Loop1 FROM L3(1TO L4(1) DO
 
EXPR(TempFor+TempBody+TempEnd);
 PRINT(); 
 PRINT(
"



                        Completed: "
+ROUND(100*(1+Loop1-L3(1))/(1+L4(1)-L3(1)),0)+" %");
END
Maybe it isn't elegant solution, but at least I know what I'm doing.

I found interesting feature (or is it bug?): list variable cannot be used as FOR-DO counter (which is a pity).

Example:
PHP Code:
LoopList:=MAKELIST(0,X,1,15);
PRINT(
LoopList); // → {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
FOR LoopList(1FROM L3(1TO L4(1) DO
  PRINT(
LoopList); // → 0 (and program stops.)
END

----
It seems the program works now with any number of inequalities and with number of variables up to 20 which is more than enough. I will test it on more caches before uploading.

Thank you again very much, Didier.

Prime G2, 15C CE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (Recursive) nested loops and IFs? - chromos - 12-17-2015 08:20 PM



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