Control Statements Flashcards
___ is an informal language that helps you develop algorithms without having to worry about the strict details of Java language syntax.
a) Pseudocode
The process of executing the statements in a program one after the other in the order in which they’re written is called ___ .
b) sequential execution.
When it’s not known in advance how many times a set of statements will be repeated, a(n) ___ value can be used to terminate the repetition.
c) sentinel, signal, flag or dummy
Java is a(n) ___ language; it requires all variables to have a type.
d) strongly typed
___ enable programs to perform statements repeatedly as long as a condition re- mains true.
e) Repetition statements
a) The if statement is a double-selection statement.
a) False. It is a single-selection statement because it selects or ignores a single action
b) Java provides the ternary operator(?:), which can be used in place of a do…while statement.
b) False. Java’s ternary operator (?:) cannot be used in place of an do…while statement.
c) A nested control statement appears in the body of another control statement.
c) True.
d) Specifying the order in which statements execute in a program is called program control.
d) True.
e) A nonfatal logic error causes a program to fail and terminate prematurely.
e) False. A nonfatal logic error allows a program to continue executing but causes it to produce in- correct results.
Typically, ___ statements are used for counter-controlled repetition and ___ statements for sentinel-controlled repetition.
a) for, while
The do…while statement tests the loop-continuation condition ___ executing the loop’s body; therefore, the body always executes at least once.
b) after
The ___ statement selects among multiple actions based on the possible values of an integer variable or expression.
c) switch
The ___ operator can be used to ensure that two conditions are both true before choosing a certain path of execution.
d) continue
If the loop-continuation condition in a for header is initially ___ , the program does not execute the for statement’s body.
e) && (conditional AND)
a) The default case is required in the switch selection statement.
a) False. The default case is optional. If no default action is needed, then there’s no need for a default case
b) The break statement is required in the last case of a switch selection statement.
b) False. The break statement is used to exit the switch statement. The break statement is not required for the last case in a switch statement
c) The expression( ( x > y ) && ( a < b ) ) is true if either x > y is true or a < b is true.
c) False. Both of the relational expressions must be true for the entire expression to be true when using the && operator
d) An expression containing the || operator is true if either or both of its operands are true.
d) True
e) Listing cases consecutively with no statements between them enables the cases to perform the same set of statements.
e) True