5. if and for Statements

Relational Operators

We have introduced quite a few new operators in this chapter, many of which are used to compare numbers. Such operators are called relational operators. In total, there are six relational operators in the C++ language. We present all of them in the following table:

Relational Operator Meaning
< less than
> greater than
<= less than or equal to
>= greater than or equal to
== equal to
!= not equal to

Now we can make a small readability improvement to our previous program. To test whether dayOfWeek is during weekend, the program used this line:

    if (dayOfWeek>5 && dayOfWeek<8)

Instead, it would be nicer to write the same condition like this:

    if (dayOfWeek>=6 && dayOfWeek<=7)

Perhaps, even better, like this:

    if (dayOfWeek==6 || dayOfWeek==7)

The symbol '&' is called the ampersand. It is a logogram, meaning that it denotes an entire word, in this case the word 'and'. In the times long past when pupils in schools recited the English alphabet by heart, the recitation would regularly end in "x,y,z and per se and". Since the alphabet is recited at a very quick pace, the phrase "and per se and" got conflated into "ampersand".

The grapheme for ampersand (&) comes from the Latin word et (which, again, means: and). It was common practice in medieval times to write the letters e and t together as a single grapheme (something that is called a ligature) which in a time span of many centuries finally deteriorated into the grapheme '&' that we use today.