If-then-else syntax issue
Posted: 19 Sep 2016 13:25
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.
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.