Recent searches
No recent searches
Cannot Use Parentheses and Math Logic in ELIF Statements
Answered
Posted Dec 05, 2022
Hello,
I'm trying to figure out why I'm unable to use parentheses and math logic within ELIF statements.
Code such as this will not work:
IF X
THEN Y
ELIF (A + B) / C = D
THEN Z
ENDIF
While this will:
IF X
THEN Y
ELIF A + B / C = D
THEN Z
ENDIF
Notice how the only difference is the parentheses. Values don't really matter, neither do the math operators or comparison operators. In fact, a comparison operator isn't even needed.
Naturally, this is mathematically different and will have different results.
For this specific case, we know that the following statements are equivalent and thus interchangeable...
(A + B) / C
A / C + B / C
...so I was able to clumsily maneuver around this issue, but it still begs the question of why this is prohibited in the first place.
1
3
3 comments
Dave Dyson (gmail)
Hi Jozef -
A couple thoughts:
You can see this method in the examples here: Nesting multiple IF THEN ELSE functions
1
Jozef
Hello Dave,
1. I did specify that those are mathematically different and will have different results. This is why I mention that the below is a mathematically equivalent workaround.
2. The example you provided does work for me, and with more testing I found the following combinations to work / not work.
I guess it's even weirder because this is not demonstrably required in the initial IF statement - only in the subsequent ELIFs.
Regardless, thank you for clearing this up - I must have been stuck hopping between 3 & 4 without trying another set of parentheses around the entire statement. What constitutes as valid and invalid doesn't seem very predictable here, and I'm glad there's at least a post now showcasing this.
The link you provided was also helpful as it does specifically state best practices, although in one case it's a best practice and in another it's a requirement.
0
Dave Dyson (gmail)
Glad I could help, Jozef!
0