I am having some confusion about if () { } else { } structures.
Sometimes it is very awkward to set up an “if” condition where the false condition is of interest, not the true.
The first snippet below works correctly, but is awkward to create (and awkward to interpret three months after coding it!)
SNIPPET 1:
If (ischecked(“ON”) == false)
{
Do Something
}
I think that the snippet below will be clearer to interpret three months after coding, but it does not appear to work.
SNIPPET 2:
If (ischecked(“ON”))
{
}
Else
{
Do something
}
The empty first set of braces creates an error. [Expression expected [82]]. The snippet works if some nonsense is inserted, such as “a=1”.
Am I missing something? It is common in other programming languages to have empty expressions inside an if-then-else structure.
If-then-else syntax issue
Moderator: Martin
Re: If-then-else syntax issue
Try this:
If NOT (ischecked(“ON”))
{do your thing};
If NOT (ischecked(“ON”))
{do your thing};
Re: If-then-else syntax issue
Nice idea, but, sadly, it does not work! 
It generates an error.
Just to be clear, the work-around that I wrote works. My issue was why the { do Nothing} creates an error. No reason for that to happen that I can think of.

It generates an error.
Just to be clear, the work-around that I wrote works. My issue was why the { do Nothing} creates an error. No reason for that to happen that I can think of.
Re: If-then-else syntax issue
Hi,
The NOT respectively ! belongs within the parenthesis. Following should work:
or
This limitation of the empty block comes from the fact that each block in Automagic has to evaluate to a value (last evaluated value of the block). I could artificially let an empty block evaluate to false or something like that but I'm not sure if this could lead to other problems.
You could also write:
Regards,
Martin
The NOT respectively ! belongs within the parenthesis. Following should work:
Code: Select all
if (!isChecked("ON"))
{
...
}
Code: Select all
if (NOT isChecked("ON"))
{
...
}
You could also write:
Code: Select all
if (...)
{
false;
}
else
{
do something...
}
Martin
Re: If-then-else syntax issue
Yes,this was what I meant. I couldn't find the right syntax from the documentation so I wrote how I remembered it. Sorry about that.Martin wrote:if (NOT isChecked("ON"))
{
...
}