Chapter 4

Additional Web Questions

Please answer the following true or false questions:

1. "Flow Control" is the decision-making process of a computer program.

2. Computers can think for themselves.

3. if statements always have a then clause.

4. if statements always have an else clause.

5. while loops always have a then clause.

6. You cannot nest flow control blocks inside each other.

7. A while loop will automatically terminate on its own.

8. The switch statement requires a String variable.

9. Each case block must have a break statement at the end.

10. To compare String values together, you should use the == operator.

Answes:

1. true.

Flow control statements direct the flow of a program. They control which parts of the program are executed, and which parts aren't.

2. false.

Computers have no intelligence. You, the programmer, in the form of flow control statements, must program all "thought."

3. true.

The statement or block immediately following the if statement is the "then" clause. Remember, in Java, there is no keyword "then" like in some other languages.

4. false.

if statements can have an else clause, but it is optional. The word "else" is a keyword and must be used when there is an else clause.

5. false.

while loops never have a then clause. They do have a "do" block that is executed while the test condition is true, however. It is similar to the then clause, but it's not called a "then clause."

6. false.

You absolutely can nest statements. This is a very common practice which can create a "tree" of possible flow paths.

7. false.

A while loop will only terminate when the test condition is false. If you don't construct your while loop so that the test condition will ever be false, then your program will go into an "infinite loop" and never exit.

8. false.

The switch statement requires a primitive "small number" type: int, char, short, and byte. Types such as String, float and double will not work.

9. false.

The break statement is optional. If you don't use one, then the program flow will "fall down" into the next case block.

10. false.

Object types should use the equals() operator to compare values. If you use the == operator, it will only tell you if the two variables are the same variable or not.