IF THEN 'true' bug
Posted: Mon Aug 30, 2021 12:03 pm
This tricky bug only shows up when evaluating two values (eg: b+c) 'true' that are not caged by parenthesis, else it hides unnoticed, giving false confidence to other code, such as the following snippet, which appears to run ok...
But both lines 2 and 3 have a bug, even though they are not failing because the IF evaluates as false, despite the ELSE of line 3 obviously being true.
Changing the value of 'a' from 11 to 1 will cause lines 2 and 3 to fail because the IF condition will then evaluate to true.
The bug can be avoided by using parenthesis, eg the following line will be ok whether it evaluates to true or false...
Code: [Local Link Removed for Guests]
a=11: b=2: c=3
if a < b+c then wlog "a<"
if a < b+c then wlog "a<" else wlog "a>"
Changing the value of 'a' from 11 to 1 will cause lines 2 and 3 to fail because the IF condition will then evaluate to true.
The bug can be avoided by using parenthesis, eg the following line will be ok whether it evaluates to true or false...
Code: [Local Link Removed for Guests]
if a < (b+c) then wlog "ok" else wlog "ok"