Send
Close Add comments:
(status displays here)
Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
C: Conditions
1. C: Conditions
2. C: Conditions
A condition is an expression that evaluates to a Boolean value - true or false. At this point, there are two main types of conditions.
relational expressions
logical or Boolean expressions
Note: An arithmetic expression evaluates to a number literal value. A string expression evaluates to a string literal value.
3. Relational expressions
Relational expressions take arithmetic, character, or logical operands and evaluate to logical values.
4. Logical expressions
Logical expressions take logical operands and evaluate to logical values.
This will be covered in more detail later.
5. Relational operators
The following table shows relational operators used to compare two values.
| Relational operators |
| Computer |
Math |
English description |
| < |
< |
less than |
| >= |
≥ |
greater than or equal to |
| <= |
≤ |
less than or equal to |
| > |
> |
greater than |
| == |
= |
equal to |
| != |
≠ |
not equal to |
6. Examples
Here are some examples of relational operators using literals. On the left is the expression. On the right is the Boolean/logical value to which it reduces.
Relational operator examples using literals |
Relational Expression |
Reduced Value |
| 2 < 3 |
true |
| 3 > 2 |
false |
| 2 >= 2 |
true |
| 2 >= 3 |
false |
| 2 <= 2 |
true |
| 3 <= 2 |
false |
| 3 == 3 |
true |
| 2 == 3 |
false |
| 3 != 3 |
false |
| 2 != 3 |
true |
Never compare floating point approximations for equality or inequality.
Never compare values of different types.
7. End of page
8. Multiple choice questions for this page
19 questions omitted (login required)