teach-ict.com logo

THE education site for computer science and ICT

3. Selection: Comparisons

Other than for the most basic tasks, most programs involve having to make choices. Maybe you want to do one thing if a condition is true and another if it is not. The process of determining which choice to take is called 'selection'.


Selection always involves a comparison operation, where you check whether certain conditions are met. These use relational operators, which we discussed in the operators section. But, to remind you, the operators you will need to know are:


Meaning Symbol
Greater than
Less than
Greater than or equal to
Less than or equal to
Not equal to
Are the same


Combine comparisons

You can use boolean operators to make two comparisons in the same statement, like this

                     a < 2 AND b > 4

The boolean AND operator means that both comparisons need to be true for the evaluation to be true. Other common boolean operators used are OR and NOT.


Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: What is selection in programming?