Post Reply 
(Recursive) nested loops and IFs?
12-18-2015, 08:06 AM (This post was last modified: 12-18-2015 09:35 AM by Didier Lachieze.)
Post: #7
RE: (Recursive) nested loops and IFs?
(12-17-2015 08:20 PM)chromos Wrote:  
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 successfully. ΠLIST is important or it may be ∑LIST too? I know, I could try it myself. :-)

In this case you have to use ΠLIST: ΠLIST(list) returns the product of the list elements which is the equivalent of a Boolean AND while ∑LIST(list) returns the sum of the list elements which is the equivalent of a Boolean OR.

Nested IF conditions can be replaced by ANDs:

PHP Code:
IF (EXPR(L5(1))>=AND EXPR(L5(1))<=9THEN
  
IF (EXPR(L5(2))>=AND EXPR(L5(2))<=9THEN
    
IF (EXPR(L5(3))>=AND EXPR(L5(3))<=9THEN 

is the same as:

PHP Code:
IF (EXPR(L5(1))>=AND EXPR(L5(1))<=9) AND (EXPR(L5(2))>=AND EXPR(L5(2))<=9) AND (EXPR(L5(3))>=AND EXPR(L5(3))<=9THEN 

EXECON("EXPR(&1)>=0 AND EXPR(&1)<=9",L5) returns a list with the result of the test for each element of L5, either 0 (false) or 1 (true).
Then ΠLIST returns the product (AND) of all these results: 0 (false) if at least one is false and 1 (true) if all are true.
As we work with lists this is not tied to the number of variables.

(12-17-2015 08:20 PM)chromos Wrote:  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.

Here L4-L3 returns a list of the differences between the elements of L4 and L3, so ΠLIST(L4-L3) returns the product of these differences which gives the total number of loops to do.
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-18-2015 08:06 AM



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