|
|
|||
|
|
|
||
|
Posted by Guy Lecky-Thompson Feb 22, 2007 |
Condition testing is essentially the way that a programming language decides the veracity of a statement. The final decision is broken down into binary values - 0 or 1, True or False. The statement may have many, many parts to it, but the end result will be binary.
Even though an IF statement (for example) might result in several different actions - IF [this] THEN DO [this] ELSEIF [this] DO [that] ELSE DO [the other] - each decision is binary. Each part of the statement is a condition test that will evaluate to True or False.
Within an IF statement, we can also have compound conditions - IF [this] OR [that] AND [the other] THEN DO [something] - and the exact way that this is evaluated to arrive at the binary conclusion follows mathematical rules. Although it is always better to put pairs in brackets, many programmers rely heavily on their mathematical backgrounds to force the 'proper' evaluation.
I would strongly recommend using brackets, if only to improve readability. That's a tip - write it down. For the novices, if you really need convincing, just remember that the following are not the same:
Example #1 : IF ([this] OR [that]) AND [the other] THEN
Example #2 : IF [this] OR ([that] AND [the other]) THEN
That is the reason we use brackets. Clarity. The article Condition Testing in BASIC Programming looks at this from the BASIC programmers perspective, and has many more tips of this ilk for other languages.
Happy coding!