Read this chapter, which reviews how computers make decisions using if statements. As you read this tutorial, you will understand that sometimes it is important to evaluate the value of an expression and perform a task if the value comes out to be true and another task if it is false. In particular, try the simulated program under the heading "Simulated Program" to see how a different response is presented to the user based on if a number is positive or negative.
Pay special attention to the "More Than One Statement per Branch" header to learn how the 'else' statement is used when there is more than one choice.
13. Boolean Expressions
Answer:
Enter your age
11
Child rate
Enjoy the show
Boolean Expressions
Relational Operators |
|
---|---|
Operator |
Meaning |
A == B |
is A equal to B ? |
A < B |
is A less than B ? |
A <= B |
is A less than or equal to B ? |
A > B |
is A Greater than B ? |
A >= B |
is A Greater than or equal to B ? |
A != B |
is A not equal to B ? |
We need to look at the condition part of the if
statement. Usually this is a boolean expression. Recall that an expression is is a combination of literals, operators, variable
names, and parentheses used to calculate a value.

Boolean expressions often compare numbers. A relational operator says how the numbers are compared.
Here are some annoying details (that will be really annoying later on if you forget about them):
- The operator for "equal" is
==
(two equal signs in a row). In your web browser it may be hard to see that there are two equal signs. - The operator for "not equal" is
!=
(exclamation point equal sign).
It is easy to forget these two details, and easy to overlook these details in a program. You might spend hours debugging a program because a =
was used where a ==
belongs.
Question 13: