Write out your answers for these questions on a separate piece of paper.
Question #1:
The if
statement is used for ____________ and comes in three
forms: ____________, ____________, and ____________.
Question #2: A(n) ____________ is treated by the compiler as a single statement, even though is consists of several statements.
Question #3:
In addition to the if
statement, C++ also provides the
blank statement for the same purpose.
Question #4:
The expression in a switch
statement must be ____________.
Question #5:
Only ____________ tests are allowed for the case
clauses of a
switch
statement.
Suppose i
and j
are both int
s set to some
values.
Code #1:
Write a boolean expression that evaluates to true
if and
only if i
is less than j
.
Code #2:
Using the boolean expression from the previous question, write an
if
statement that prints "Too small!" when i
is less
than j
.
Code #3:
Adding to the previous question, write a new if
statement
that also prints "Too big!" when i
is not less
than j
.
Code #4:
Adding to the previous question, write yet another new if
statement that prints "Just right." (not "Too big!") when i
is equal to j
.
Code #5:
Why can't you turn any of these if
statements into
switch
statements?