Inside Collection (Course): Object-Oriented Programming (OOP) with Java
Summary: This module contains review questions and answers keyed to the module titled Jb0230: Java OOP: Flow of Control.
This module contains review questions and answers keyed to the module titled Jb0230: Java OOP: Flow of Control .
The questions and the answers are connected by hyperlinks to make it easy for you to navigate from the question to the answer and back again.
List and describe eight of the statements used in Java programs to alter or control the logical flow of the program.
Provide pseudo-code that illustrates the general syntax of a while statement.
True or false? During the execution of a while statement, the program will continue to execute the statement or compound statement for as long as the conditional expression evaluates to true, or until a break or continue statement is encountered. If false, explain why.
True or false? A while loop is an entry condition loop. If false, explain why.
What is the significance of an entry condition loop?
Provide pseudo-code illustrating the general syntax of the if-else statement.
Provide pseudo-code illustrating the general syntax of the switch-case statement.
Describe the behavior of a switch-case statement. Provide a pseudo-code fragment that illustrates your description of the behavior. Do not include a description of labeled break statements.
What are the three actions normally involved in the operation of a loop (in addition to executing the code in the body of the loop) ?
True or false? A for loop header consists of three clauses separated by colons. If false, explain why.
Provide pseudo-code illustrating the general syntax of a for loop
True or false? In a for loop, the first and third clauses within the parentheses can contain one or more expressions, separated by the comma operator. If False, explain why.
What is the guarantee made by the comma operator ?
True or false? The expressions within the first clause in the parentheses in a for loop are executed only once during each iteration of the loop. If false, explain why.
While any legal expression(s) may be contained in the first clause within the parentheses of a for loop, the first clause has a specific purpose. What is that purpose?
True or false? Variables can be declared and initialized within the first clause in the parentheses of a for loop. If false, explain why.
True or false? The second clause in the parentheses of a for loop consists of a single expression which must eventually evaluate to true to cause the loop to terminate. If false, explain why.
True or false? A for loop is an exit condition loop. If false, explain why.
True or false? Because a for loop is an entry condition loop, the third clause inside the parentheses is executed at the beginning of each iteration. If false, explain why.
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.
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 the same 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.
True.
True.
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 completed execution. This is an important point since this clause is typically used to update the control variable, and perhaps other variables as well. If variables are 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 the body is completed.
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.
False. The second clause consists of a single expression which must eventually evaluate to false (not true) to cause the loop to terminate.
True.
Typically the first clause is used for initialization. The intended purpose of the first clause is initialization.
False. The expressions in the first clause are executed only once, at the beginning of the loop, regardless of the number of iterations.
The comma operator guarantees that its left operand will be executed before its right operand.
True.
The general syntax of a for loop follows:
for (first clause; second clause; third clause)
single or compound statementFalse: A for loop header consists of three clauses separated by semicolons, not colons.
The operation of a loop normally involves the following three actions in addition to executing the code in the body of the loop:
The pseudo-code fragment follows:
switch(expression){
case constant:
sequence of optional statements
break; //optional
case constant:
sequence of optional statements
break; //optional
.
.
.
default //optional
sequence of optional statements
}An expression is tested against a series of unique integer constants. If a match is found, the sequence of optional statements associated with the matching constant is executed. Execution of statements continues until an optional break is encountered. When break is encountered, execution of the switch statement is terminated and control is passed to the next statement following the switch statement.
If no match is found and the optional default keyword along with a sequence of optional statements has been provided, those statements will be executed.
The general syntax of the switch-case statement follows:
switch(expression){
case constant:
sequence of optional statements
break; //optional
case constant:
sequence of optional statements
break; //optional
.
.
.
default //optional
sequence of optional statements
}The general syntax of the if-else statement is:
if(conditional expression)
statement or compound statement;
else //optional
statement or compound statement; //optionalThe significance of an entry condition loop is that the conditional expression is tested before the statements in the loop are executed. If it tests false initially, the statements in the loop will not be executed.
True.
True.
The general syntax of a while statement follows :
while (conditional expression)
statement or compound statement;The following table lists the statements supported by Java for controlling the logical flow of the program.
Statement Typeif-else selection
switch-case selection
for loop
for-each loop
while loop
do-while loop
try-catch-finally exception handling
throw exception handling
break miscellaneous
continue miscellaneous
label: miscellaneous
return miscellaneous
goto reserved by Java but not supportedThis section contains a variety of miscellaneous information.
Financial : Although the Connexions site makes it possible for you to download a PDF file for this module at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should be aware that some of the HTML elements in this module may not translate well into PDF.
I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.
In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. I neither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please be aware that it is a copy of a module that is freely available on cnx.org and that it was made and published without my prior knowledge.
Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.
-end-