Conditions : True or False
Probably all programming languages depend on conditions. A condition is the most basic feature programming possesses. It allows programs to behave in a dynamic manner. These are like pathways being split up everytime decisions have to be made. Basically, conditions return only values either True or False. Below is an example of a condition:
45 equals 29. X
Of course, in mathematics, this is not true. Since 45 is a number with a different value than 29. Therefore, the above condition returns False, while below returns True.
A equals A. True. √
In a Boolean logic (programming), True and False have corresponding values. Always remember, that True has a mathematical value of 1, while False has a value of 0. If you come to think of it, 1 and 0 are the accepted values of a computer, much more popularly known as Binary numbers. Now don’t disregard this very useful fact, since you might be handling complicated conditions in the future, and you may be able to take advantage of this information.
Now how are these conditions being used in programming?
Later you will be able to meet certain programming statements such as "If, Else, ElseIf", or "Do While, Loop", or "Select Case, or switch". These statements always follow conditions. Without conditions, you can’t put them to work. A simple explanation about how they can be used is as follows:
Perhaps you are to attend on a scheduled meeting. There are some things to consider especially those which depend on certain occurrences. You have prepared different sets of plans, which you designed specifically for a certain event. Suppose you have Plan A and Plan B. That, if there will only be at most 10 people to show up in the meeting, you will execute Plan A, but, if there will more than 10 people to attend the meeting, then you will proceed immediately to Plan B. Now there’s already the condition. Of course, with the set condition, if and only if that there are at most 10 people to show up, you will definitely execute Plan A, if not, then you go for Plan B.
In programming, these conditions are being put to code using Conditional Operators. Here’s a list of common conditional operators:
| = / == | Is equal to | |
| > | Is greater than | |
| < | Is less than | |
| >= | Is equal or greater than | |
| <= | Is equal or less than |
There is also a conditional operator which negates any condition as listed above. This is the operator "Not", having a symbol in C / C++ as "!" or an Exclamation Point. Negation is by means of converting the condition into its opposite value. If True is being negated, then it becomes False, while it does the otherwise.
So, if you put the condtions given as example at the early part of this article into code, it should look like this:
45 = 49 (for Visual Basic) or 45 == 49 (for C / C++), returning False
A = A or A == A, returning True
If you have questions or perhaps clarifications, please leave ‘em all here.
