Question 18
True or false? A for loop is an exit condition loop. If false, explain why.
Question 19
True or false? Because a for loop is an entry condition loop, the third clause inside the parentheses is executed at the beginning ofeach iteration. If false, explain why.
Question 20
True or false? A return statement is used to terminate a method and (optionally) return a value to the calling method. If False, explain why.
Question 21
True or false? Exception handling modifies the flow of control of a Java program. If false, explain why.
What is the meaning of the following two images?
This image was inserted here simply to insert some space between the questions and the answers to keep them from being visible on the screen at thesame time.
The image is also an example of the kinds of things that we do in my course titled ITSE 2321, Object-Oriented Programming.
This image was also inserted for the purpose of inserting space between the questions and the answers.
Answers
Answer 21
True.
Answer 20
True.
Answer 19
False. Although the third clause appears physically at the top of the loop, it isn't executed until the statements in the body of the loop have completedexecution. This is an important point since this clause is typically used to update the control variable, and perhaps other variables as well. If variablesare updated in the third clause and used in the body of the loop, it is important to understand that they do not get updated until the execution of thebody is completed.
Answer 18
False. The value of the second clause is tested when the statement first begins execution, and at the beginning of each iteration thereafter. Therefore,the for loop is an entry condition loop.
Answer 17
False. The second clause consists of a single expression which must eventually evaluate to false (not true) to cause the loop to terminate.
Answer 16
True.
Answer 15
Typically the first clause is used for initialization. The intended purpose of the first clause is initialization.
Answer 14
False. The expressions in the first clause are executed only once, at the beginning of the loop, regardless of the number of iterations.
Answer 13
The comma operator guarantees that its left operand will be executed before its right operand.
Answer 12
True.
Answer 11
The general syntax of a for loop follows:
for (first clause; second clause; third clause)
single or compound statement
Answer 10
False: A for loop header consists of three clauses separated by semicolons, not colons.
Answer 9
The operation of a loop normally involves the following three actions in addition to executing the code in the body of the loop:
- Initialize a control variable.
- Test the control variable in a conditional expression.
- Update the control variable.