Deck 6: Looping

Full screen (f)
exit full mode
Question
It is important that the loop control ____ be altered within the body of the loop.

A) value
B) variable
C) constant
D) argument
Use Space or
up arrow
down arrow
to flip the card.
Question
Before entering a loop, the first input statement, or ____, is retrieved.

A) empty body
B) posttest loop
C) loop body
D) priming read
Question
A counted loop is the same as an indefinite loop.
Question
Many seasoned programmers start counter values at 1 because they are used to doing so when working with arrays.
Question
Making a comparison to 0 is slower than making a comparison to any other value.
Question
Use a(n) ____ loop to execute a body of statements continually as long as the Boolean expression that controls entry into the loop continues to be true .

A) empty
B) while
C) definite
D) control
Question
Programmers rarely use indefinite loops when validating input data.
Question
When nesting loops, the variable in the outer loop changes more frequently.
Question
A(n) ____ is a kind of indefinite loop.

A) counter-controlled
B) event-controlled
C) initialized
D) validating
Question
You can use virtually any number of nested loops; however, at some point, your machine will no longer be able to store all the necessary looping information.
Question
On many keyboards, the Break key is also the ____ key.

A) Pause
B) Esc
C) Delete
D) Ctrl
Question
You can initialize one or more variables in the first section of a  for  statement.
Question
The statements that make up a loop body will continue to execute as long as the expression value remains false.
Question
Which is an infinite loop?

A) loopCount = 5; while(loopCount > 3);
{
   System.out.println("Hello");
   loopCount = loopCount - 1;
}
B) loopCount = 1; while(loopCount < 3);
{
   System.out.println("Hello");
}
C) loopCount = 4; while(loopCount < 3);
{
   System.out.println("Hello");
   loopCount = loopCount + 1;
}
D) loopCount = 1; while(loopCount < 3);
{
   System.out.println("Hello");
   loopCount = loopCount + 1;
}
Question
In order to improve loop performance, it's important to make sure the loop does not include unnecessary operations or statements.
Question
A ____ is a structure that allows repeated execution of a block of statements.

A) body
B) Boolean expression
C) loop
D) loop control
Question
A loop controlled by the user is a type of ____ loop.

A) indefinite
B) definite
C) counter-controlled
D) incrementing
Question
____ is the process of ensuring that a value falls within a specified range.

A) Value checking
B) Data integrity
C) Validating data
D) Syntax checking
Question
A loop that never ends is called a(n) ____ loop.

A) definite
B) infinite
C) while
D) for
Question
Shortcut operators are a programmer's only choice when incrementing or accumulating a variable's value.
Question
A(n) ____ loop is a special loop that is used when a definite number of loop iterations is required.

A) while
B) for
C) else
D) do…while
Question
What is wrong with the following code? x=1;
While (x<5);
 { System.out.println (x);
   x++;
}

A) Syntax error in the println method
B) Incorrect use of prefix increment operator
C) Semicolon at the end of the while expression
D) Incorrect initialization
Question
The ____ loop is the posttest loop used in Java.

A) for
B) counter-controlled
C) while
D) do...while
Question
Assume  d and x are integers: d = 5;
X = 2 * ++d;
What is the value of x ?

A) 10
B) 11
C) 12
D) 13
Question
With ____ loops, the order of the conditional expressions can be important.

A) nested
B) posttest
C) pretest
D) indefinite
Question
When creating a for loop, which statement will correctly initialize more than one variable?

A) for a=1, b=2
B) for(a=1; b=2)
C) for(a=1, b=2)
D) for(a = 1&& b = 2)
Question
A(n) ____ loop is one that performs no actions other than looping.

A) nested
B) do-nothing
C) indefinite
D) posttest
Question
One execution of any loop is called a(n) ____.

A) run
B) loop
C) prime
D) iteration
Question
The ____ loop checks the value of the loop control variable at the bottom of the loop after one repetition has occurred.

A) while
B) do…while
C) for
D) else
Question
____ is a technique that can improve loop performance by combining two loops into one.

A) Loop fusion
B) Prefix incrementing
C) Short-circuit evaluation
D) Do-nothing looping
Question
When you want to increase a variable's value by exactly 1, use the ____.

A) power statement
B) accumulating operator
C) binary operators
D) prefix increment operator
Question
In the expressions b = 8 and c = --b , what value will be assigned to the variable c ?

A) 7
B) 8
C) 9
D) 10
Question
You can initialize more than one variable in a for loop by placing a(n) ____ between the separate statements.

A) semicolon
B) equal sign
C) period
D) comma
Question
A for loop provides a convenient way to create a(n) ____ loop.

A) counter-controlled
B) posttest
C) while
D) infinite
Question
A(n) ____ is a body with no statements in it.

A) infinite loop
B) empty body
C) finite loop
D) event-controlled loop
Question
In a do…while loop, the loop will continue to execute until ____.

A) the loop control variable is true
B) the loop control variable is false
C) the user types EXIT
D) the program terminates
Question
Which of the following is NOT a valid method to increase a variable named score by 1?

A) ++score
B) score++
C) ++score = score + 1
D) score = score + 1
Question
You use a unary minus sign preceding a value to make the value ____.

A) negative
B) positive
C) valid
D) constant
Question
How many times will outputLabel be called? for(customer = 1; customer <= 20; ++customer)
     for(color = 1; color <= 3; ++color)
          outputLabel();

A) 0
B) 3
C) 20
D) 60
Question
The process of repeatedly increasing a value by some amount is known as ____.

A) checking
B) adding
C) accumulating
D) containing
Question
Match between columns
The technique of combining two loops into one
prefix ++
The technique of combining two loops into one
block
The technique of combining two loops into one
definite loop
The technique of combining two loops into one
loop control variable
The technique of combining two loops into one
binary operators
The technique of combining two loops into one
loop fusion
The technique of combining two loops into one
decrementing
The technique of combining two loops into one
for loop
The technique of combining two loops into one
sleep() method
The technique of combining two loops into one
empty body
The technique of combining two loops into one
do-nothing loop
The technique of combining two loops into one
*=
The technique of combining two loops into one
data validation
The technique of combining two loops into one
accumulating
The technique of combining two loops into one
% =
Question
What is wrong with the following code? while (4>2)
 System.out.println ("Hi there");

A) missing curly braces
B) illegal conditional expression
C) infinite loop
D) Syntax error in the output statement
Question
Match between columns
Within parentheses are three sections separated by exactly two semicolons
prefix ++
Within parentheses are three sections separated by exactly two semicolons
block
Within parentheses are three sections separated by exactly two semicolons
definite loop
Within parentheses are three sections separated by exactly two semicolons
loop control variable
Within parentheses are three sections separated by exactly two semicolons
binary operators
Within parentheses are three sections separated by exactly two semicolons
loop fusion
Within parentheses are three sections separated by exactly two semicolons
decrementing
Within parentheses are three sections separated by exactly two semicolons
for loop
Within parentheses are three sections separated by exactly two semicolons
sleep() method
Within parentheses are three sections separated by exactly two semicolons
empty body
Within parentheses are three sections separated by exactly two semicolons
do-nothing loop
Within parentheses are three sections separated by exactly two semicolons
*=
Within parentheses are three sections separated by exactly two semicolons
data validation
Within parentheses are three sections separated by exactly two semicolons
accumulating
Within parentheses are three sections separated by exactly two semicolons
% =
Question
Match between columns
A counted loop
prefix ++
A counted loop
block
A counted loop
definite loop
A counted loop
loop control variable
A counted loop
binary operators
A counted loop
loop fusion
A counted loop
decrementing
A counted loop
for loop
A counted loop
sleep() method
A counted loop
empty body
A counted loop
do-nothing loop
A counted loop
*=
A counted loop
data validation
A counted loop
accumulating
A counted loop
% =
Question
Match between columns
Operate on two values
prefix ++
Operate on two values
block
Operate on two values
definite loop
Operate on two values
loop control variable
Operate on two values
binary operators
Operate on two values
loop fusion
Operate on two values
decrementing
Operate on two values
for loop
Operate on two values
sleep() method
Operate on two values
empty body
Operate on two values
do-nothing loop
Operate on two values
*=
Operate on two values
data validation
Operate on two values
accumulating
Operate on two values
% =
Question
Match between columns
A body with no statements
prefix ++
A body with no statements
block
A body with no statements
definite loop
A body with no statements
loop control variable
A body with no statements
binary operators
A body with no statements
loop fusion
A body with no statements
decrementing
A body with no statements
for loop
A body with no statements
sleep() method
A body with no statements
empty body
A body with no statements
do-nothing loop
A body with no statements
*=
A body with no statements
data validation
A body with no statements
accumulating
A body with no statements
% =
Question
What is the output of the following code: loopCount = 1;
While(loopCount < 3)
{
   System.out.println("Hello");
   loopCount = loopCount + 1;
}

A) Hello
B) Hello Hello
C) Hello Hello
Hello
D) HelloHello
Question
What is the output of the following code: for (loop = 1; loop <3; ++loop)
   System.out.print(1);
   for (loop2 = 1; loop2< 3; ++loop2)
      System.out.print(2);

A) 112222
B) 1232212322
C) 122122
D) 122212221222
Question
Match between columns
Part of the Thread class in the java.lang package
prefix ++
Part of the Thread class in the java.lang package
block
Part of the Thread class in the java.lang package
definite loop
Part of the Thread class in the java.lang package
loop control variable
Part of the Thread class in the java.lang package
binary operators
Part of the Thread class in the java.lang package
loop fusion
Part of the Thread class in the java.lang package
decrementing
Part of the Thread class in the java.lang package
for loop
Part of the Thread class in the java.lang package
sleep() method
Part of the Thread class in the java.lang package
empty body
Part of the Thread class in the java.lang package
do-nothing loop
Part of the Thread class in the java.lang package
*=
Part of the Thread class in the java.lang package
data validation
Part of the Thread class in the java.lang package
accumulating
Part of the Thread class in the java.lang package
% =
Question
Match between columns
Remainder and assign
prefix ++
Remainder and assign
block
Remainder and assign
definite loop
Remainder and assign
loop control variable
Remainder and assign
binary operators
Remainder and assign
loop fusion
Remainder and assign
decrementing
Remainder and assign
for loop
Remainder and assign
sleep() method
Remainder and assign
empty body
Remainder and assign
do-nothing loop
Remainder and assign
*=
Remainder and assign
data validation
Remainder and assign
accumulating
Remainder and assign
% =
Question
Match between columns
Performs no actions in its body
prefix ++
Performs no actions in its body
block
Performs no actions in its body
definite loop
Performs no actions in its body
loop control variable
Performs no actions in its body
binary operators
Performs no actions in its body
loop fusion
Performs no actions in its body
decrementing
Performs no actions in its body
for loop
Performs no actions in its body
sleep() method
Performs no actions in its body
empty body
Performs no actions in its body
do-nothing loop
Performs no actions in its body
*=
Performs no actions in its body
data validation
Performs no actions in its body
accumulating
Performs no actions in its body
% =
Question
Match between columns
Repeatedly increasing a value by an amount
prefix ++
Repeatedly increasing a value by an amount
block
Repeatedly increasing a value by an amount
definite loop
Repeatedly increasing a value by an amount
loop control variable
Repeatedly increasing a value by an amount
binary operators
Repeatedly increasing a value by an amount
loop fusion
Repeatedly increasing a value by an amount
decrementing
Repeatedly increasing a value by an amount
for loop
Repeatedly increasing a value by an amount
sleep() method
Repeatedly increasing a value by an amount
empty body
Repeatedly increasing a value by an amount
do-nothing loop
Repeatedly increasing a value by an amount
*=
Repeatedly increasing a value by an amount
data validation
Repeatedly increasing a value by an amount
accumulating
Repeatedly increasing a value by an amount
% =
Question
Match between columns
Multiply and assign
prefix ++
Multiply and assign
block
Multiply and assign
definite loop
Multiply and assign
loop control variable
Multiply and assign
binary operators
Multiply and assign
loop fusion
Multiply and assign
decrementing
Multiply and assign
for loop
Multiply and assign
sleep() method
Multiply and assign
empty body
Multiply and assign
do-nothing loop
Multiply and assign
*=
Multiply and assign
data validation
Multiply and assign
accumulating
Multiply and assign
% =
Question
What is the output of the following code:​ loopCount = 1;
While(loopCount < 3)
   System.out.println("Hello");
   loopCount = loopCount + 1;

A) No output
B) Hello Hello
C) Hello Hello
Hello
D) This is an infinite loop
Question
Match between columns
A shortcut for incrementing and accumulating
prefix ++
A shortcut for incrementing and accumulating
block
A shortcut for incrementing and accumulating
definite loop
A shortcut for incrementing and accumulating
loop control variable
A shortcut for incrementing and accumulating
binary operators
A shortcut for incrementing and accumulating
loop fusion
A shortcut for incrementing and accumulating
decrementing
A shortcut for incrementing and accumulating
for loop
A shortcut for incrementing and accumulating
sleep() method
A shortcut for incrementing and accumulating
empty body
A shortcut for incrementing and accumulating
do-nothing loop
A shortcut for incrementing and accumulating
*=
A shortcut for incrementing and accumulating
data validation
A shortcut for incrementing and accumulating
accumulating
A shortcut for incrementing and accumulating
% =
Question
Match between columns
Ensuring that a value is in a range
prefix ++
Ensuring that a value is in a range
block
Ensuring that a value is in a range
definite loop
Ensuring that a value is in a range
loop control variable
Ensuring that a value is in a range
binary operators
Ensuring that a value is in a range
loop fusion
Ensuring that a value is in a range
decrementing
Ensuring that a value is in a range
for loop
Ensuring that a value is in a range
sleep() method
Ensuring that a value is in a range
empty body
Ensuring that a value is in a range
do-nothing loop
Ensuring that a value is in a range
*=
Ensuring that a value is in a range
data validation
Ensuring that a value is in a range
accumulating
Ensuring that a value is in a range
% =
Question
Match between columns
Subtracting 1 from a variable
prefix ++
Subtracting 1 from a variable
block
Subtracting 1 from a variable
definite loop
Subtracting 1 from a variable
loop control variable
Subtracting 1 from a variable
binary operators
Subtracting 1 from a variable
loop fusion
Subtracting 1 from a variable
decrementing
Subtracting 1 from a variable
for loop
Subtracting 1 from a variable
sleep() method
Subtracting 1 from a variable
empty body
Subtracting 1 from a variable
do-nothing loop
Subtracting 1 from a variable
*=
Subtracting 1 from a variable
data validation
Subtracting 1 from a variable
accumulating
Subtracting 1 from a variable
% =
Question
What kind of loop is this: response = keyboard.nextInt();
While (response == 1)
{
    System.out.print ("Enter 1 to continue; 0 to stop");
    response = keyboard.nextInt();
}

A) posttest
B) definite
C) event-driven
D) counted
Question
Match between columns
The value that determines whether loop execution continues
prefix ++
The value that determines whether loop execution continues
block
The value that determines whether loop execution continues
definite loop
The value that determines whether loop execution continues
loop control variable
The value that determines whether loop execution continues
binary operators
The value that determines whether loop execution continues
loop fusion
The value that determines whether loop execution continues
decrementing
The value that determines whether loop execution continues
for loop
The value that determines whether loop execution continues
sleep() method
The value that determines whether loop execution continues
empty body
The value that determines whether loop execution continues
do-nothing loop
The value that determines whether loop execution continues
*=
The value that determines whether loop execution continues
data validation
The value that determines whether loop execution continues
accumulating
The value that determines whether loop execution continues
% =
Question
Match between columns
Multiple statements within curly braces
prefix ++
Multiple statements within curly braces
block
Multiple statements within curly braces
definite loop
Multiple statements within curly braces
loop control variable
Multiple statements within curly braces
binary operators
Multiple statements within curly braces
loop fusion
Multiple statements within curly braces
decrementing
Multiple statements within curly braces
for loop
Multiple statements within curly braces
sleep() method
Multiple statements within curly braces
empty body
Multiple statements within curly braces
do-nothing loop
Multiple statements within curly braces
*=
Multiple statements within curly braces
data validation
Multiple statements within curly braces
accumulating
Multiple statements within curly braces
% =
Question
Why would a loop with altered user input be considered a type of indefinite loop? Give an example.
Question
What would happen if a semicolon is mistakenly placed at the end of a partial statement of a while loop with a Boolean expression and with an empty body?
Question
Explain why an infinite loop might not actually execute infinitely.
Question
How could a programmer identify and escape from an infinite loop?
Question

while(count < getNumberOfEmployees())
Examine the statement above. Write the code that will result in more efficient program execution assuming the result of getNumberOfEmployees() stays the same.
Question
How are indefinite loops used for validating data? Why is a loop structure typically the better choice for validating data than an if statement?
Question
How does a for loop work?
Question
Describe how a loop is controlled by a Boolean expression.
Question
Provide a code example of a pretest loop and an example of a posttest loop.
Question
What are some unconventional uses of the three sections inside the parentheses of a  for loop? Show at least three examples using code.
Question
What is loop fusion? Write a code segment that uses loop fusion to call two methods, method1 and method2 , 10 times each.
Question
counterLoop = 1;
while(counterLoop < 10);
{
     System.out.println("Hello");
     counterLoop = counterLoop + 1;
}
What is the problem in the above while loop? How would you correct the problem?
Question
public class IncrDemo
{
    public static void main(String[] args)
    {
      int myVal, yourVal;
      myVal = 10;
      System.out.println("My initial value is " + myVal);
      yourVal = ++myVal;
      System.out.println("My new value is " + myVal);
      System.out.println("Your value is " + yourVal):
    }
}
Using the above code, describe how the three println output commands will appear. Explain the values stored in the variables during code execution.
Question
How are nested loops implemented in a loop structure?
Question
while(10 > 1)
{
   System.out.println("This prints forever.");
}
Identify the problem that exists in the above while loop.
Question
​What are the three sections inside the parentheses of a for loop typically used for?
Question
How could you rewrite the following code to have the arithmetic performed only once, even if the loop executes 1,000 times?
while (x < a + b)
// loop body
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/77
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 6: Looping
1
It is important that the loop control ____ be altered within the body of the loop.

A) value
B) variable
C) constant
D) argument
B
2
Before entering a loop, the first input statement, or ____, is retrieved.

A) empty body
B) posttest loop
C) loop body
D) priming read
D
3
A counted loop is the same as an indefinite loop.
False
4
Many seasoned programmers start counter values at 1 because they are used to doing so when working with arrays.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
5
Making a comparison to 0 is slower than making a comparison to any other value.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
6
Use a(n) ____ loop to execute a body of statements continually as long as the Boolean expression that controls entry into the loop continues to be true .

A) empty
B) while
C) definite
D) control
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
7
Programmers rarely use indefinite loops when validating input data.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
8
When nesting loops, the variable in the outer loop changes more frequently.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
9
A(n) ____ is a kind of indefinite loop.

A) counter-controlled
B) event-controlled
C) initialized
D) validating
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
10
You can use virtually any number of nested loops; however, at some point, your machine will no longer be able to store all the necessary looping information.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
11
On many keyboards, the Break key is also the ____ key.

A) Pause
B) Esc
C) Delete
D) Ctrl
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
12
You can initialize one or more variables in the first section of a  for  statement.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
13
The statements that make up a loop body will continue to execute as long as the expression value remains false.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
14
Which is an infinite loop?

A) loopCount = 5; while(loopCount > 3);
{
   System.out.println("Hello");
   loopCount = loopCount - 1;
}
B) loopCount = 1; while(loopCount < 3);
{
   System.out.println("Hello");
}
C) loopCount = 4; while(loopCount < 3);
{
   System.out.println("Hello");
   loopCount = loopCount + 1;
}
D) loopCount = 1; while(loopCount < 3);
{
   System.out.println("Hello");
   loopCount = loopCount + 1;
}
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
15
In order to improve loop performance, it's important to make sure the loop does not include unnecessary operations or statements.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
16
A ____ is a structure that allows repeated execution of a block of statements.

A) body
B) Boolean expression
C) loop
D) loop control
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
17
A loop controlled by the user is a type of ____ loop.

A) indefinite
B) definite
C) counter-controlled
D) incrementing
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
18
____ is the process of ensuring that a value falls within a specified range.

A) Value checking
B) Data integrity
C) Validating data
D) Syntax checking
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
19
A loop that never ends is called a(n) ____ loop.

A) definite
B) infinite
C) while
D) for
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
20
Shortcut operators are a programmer's only choice when incrementing or accumulating a variable's value.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
21
A(n) ____ loop is a special loop that is used when a definite number of loop iterations is required.

A) while
B) for
C) else
D) do…while
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
22
What is wrong with the following code? x=1;
While (x<5);
 { System.out.println (x);
   x++;
}

A) Syntax error in the println method
B) Incorrect use of prefix increment operator
C) Semicolon at the end of the while expression
D) Incorrect initialization
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
23
The ____ loop is the posttest loop used in Java.

A) for
B) counter-controlled
C) while
D) do...while
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
24
Assume  d and x are integers: d = 5;
X = 2 * ++d;
What is the value of x ?

A) 10
B) 11
C) 12
D) 13
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
25
With ____ loops, the order of the conditional expressions can be important.

A) nested
B) posttest
C) pretest
D) indefinite
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
26
When creating a for loop, which statement will correctly initialize more than one variable?

A) for a=1, b=2
B) for(a=1; b=2)
C) for(a=1, b=2)
D) for(a = 1&& b = 2)
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
27
A(n) ____ loop is one that performs no actions other than looping.

A) nested
B) do-nothing
C) indefinite
D) posttest
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
28
One execution of any loop is called a(n) ____.

A) run
B) loop
C) prime
D) iteration
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
29
The ____ loop checks the value of the loop control variable at the bottom of the loop after one repetition has occurred.

A) while
B) do…while
C) for
D) else
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
30
____ is a technique that can improve loop performance by combining two loops into one.

A) Loop fusion
B) Prefix incrementing
C) Short-circuit evaluation
D) Do-nothing looping
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
31
When you want to increase a variable's value by exactly 1, use the ____.

A) power statement
B) accumulating operator
C) binary operators
D) prefix increment operator
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
32
In the expressions b = 8 and c = --b , what value will be assigned to the variable c ?

A) 7
B) 8
C) 9
D) 10
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
33
You can initialize more than one variable in a for loop by placing a(n) ____ between the separate statements.

A) semicolon
B) equal sign
C) period
D) comma
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
34
A for loop provides a convenient way to create a(n) ____ loop.

A) counter-controlled
B) posttest
C) while
D) infinite
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
35
A(n) ____ is a body with no statements in it.

A) infinite loop
B) empty body
C) finite loop
D) event-controlled loop
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
36
In a do…while loop, the loop will continue to execute until ____.

A) the loop control variable is true
B) the loop control variable is false
C) the user types EXIT
D) the program terminates
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
37
Which of the following is NOT a valid method to increase a variable named score by 1?

A) ++score
B) score++
C) ++score = score + 1
D) score = score + 1
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
38
You use a unary minus sign preceding a value to make the value ____.

A) negative
B) positive
C) valid
D) constant
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
39
How many times will outputLabel be called? for(customer = 1; customer <= 20; ++customer)
     for(color = 1; color <= 3; ++color)
          outputLabel();

A) 0
B) 3
C) 20
D) 60
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
40
The process of repeatedly increasing a value by some amount is known as ____.

A) checking
B) adding
C) accumulating
D) containing
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
41
Match between columns
The technique of combining two loops into one
prefix ++
The technique of combining two loops into one
block
The technique of combining two loops into one
definite loop
The technique of combining two loops into one
loop control variable
The technique of combining two loops into one
binary operators
The technique of combining two loops into one
loop fusion
The technique of combining two loops into one
decrementing
The technique of combining two loops into one
for loop
The technique of combining two loops into one
sleep() method
The technique of combining two loops into one
empty body
The technique of combining two loops into one
do-nothing loop
The technique of combining two loops into one
*=
The technique of combining two loops into one
data validation
The technique of combining two loops into one
accumulating
The technique of combining two loops into one
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
42
What is wrong with the following code? while (4>2)
 System.out.println ("Hi there");

A) missing curly braces
B) illegal conditional expression
C) infinite loop
D) Syntax error in the output statement
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
43
Match between columns
Within parentheses are three sections separated by exactly two semicolons
prefix ++
Within parentheses are three sections separated by exactly two semicolons
block
Within parentheses are three sections separated by exactly two semicolons
definite loop
Within parentheses are three sections separated by exactly two semicolons
loop control variable
Within parentheses are three sections separated by exactly two semicolons
binary operators
Within parentheses are three sections separated by exactly two semicolons
loop fusion
Within parentheses are three sections separated by exactly two semicolons
decrementing
Within parentheses are three sections separated by exactly two semicolons
for loop
Within parentheses are three sections separated by exactly two semicolons
sleep() method
Within parentheses are three sections separated by exactly two semicolons
empty body
Within parentheses are three sections separated by exactly two semicolons
do-nothing loop
Within parentheses are three sections separated by exactly two semicolons
*=
Within parentheses are three sections separated by exactly two semicolons
data validation
Within parentheses are three sections separated by exactly two semicolons
accumulating
Within parentheses are three sections separated by exactly two semicolons
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
44
Match between columns
A counted loop
prefix ++
A counted loop
block
A counted loop
definite loop
A counted loop
loop control variable
A counted loop
binary operators
A counted loop
loop fusion
A counted loop
decrementing
A counted loop
for loop
A counted loop
sleep() method
A counted loop
empty body
A counted loop
do-nothing loop
A counted loop
*=
A counted loop
data validation
A counted loop
accumulating
A counted loop
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
45
Match between columns
Operate on two values
prefix ++
Operate on two values
block
Operate on two values
definite loop
Operate on two values
loop control variable
Operate on two values
binary operators
Operate on two values
loop fusion
Operate on two values
decrementing
Operate on two values
for loop
Operate on two values
sleep() method
Operate on two values
empty body
Operate on two values
do-nothing loop
Operate on two values
*=
Operate on two values
data validation
Operate on two values
accumulating
Operate on two values
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
46
Match between columns
A body with no statements
prefix ++
A body with no statements
block
A body with no statements
definite loop
A body with no statements
loop control variable
A body with no statements
binary operators
A body with no statements
loop fusion
A body with no statements
decrementing
A body with no statements
for loop
A body with no statements
sleep() method
A body with no statements
empty body
A body with no statements
do-nothing loop
A body with no statements
*=
A body with no statements
data validation
A body with no statements
accumulating
A body with no statements
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
47
What is the output of the following code: loopCount = 1;
While(loopCount < 3)
{
   System.out.println("Hello");
   loopCount = loopCount + 1;
}

A) Hello
B) Hello Hello
C) Hello Hello
Hello
D) HelloHello
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
48
What is the output of the following code: for (loop = 1; loop <3; ++loop)
   System.out.print(1);
   for (loop2 = 1; loop2< 3; ++loop2)
      System.out.print(2);

A) 112222
B) 1232212322
C) 122122
D) 122212221222
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
49
Match between columns
Part of the Thread class in the java.lang package
prefix ++
Part of the Thread class in the java.lang package
block
Part of the Thread class in the java.lang package
definite loop
Part of the Thread class in the java.lang package
loop control variable
Part of the Thread class in the java.lang package
binary operators
Part of the Thread class in the java.lang package
loop fusion
Part of the Thread class in the java.lang package
decrementing
Part of the Thread class in the java.lang package
for loop
Part of the Thread class in the java.lang package
sleep() method
Part of the Thread class in the java.lang package
empty body
Part of the Thread class in the java.lang package
do-nothing loop
Part of the Thread class in the java.lang package
*=
Part of the Thread class in the java.lang package
data validation
Part of the Thread class in the java.lang package
accumulating
Part of the Thread class in the java.lang package
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
50
Match between columns
Remainder and assign
prefix ++
Remainder and assign
block
Remainder and assign
definite loop
Remainder and assign
loop control variable
Remainder and assign
binary operators
Remainder and assign
loop fusion
Remainder and assign
decrementing
Remainder and assign
for loop
Remainder and assign
sleep() method
Remainder and assign
empty body
Remainder and assign
do-nothing loop
Remainder and assign
*=
Remainder and assign
data validation
Remainder and assign
accumulating
Remainder and assign
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
51
Match between columns
Performs no actions in its body
prefix ++
Performs no actions in its body
block
Performs no actions in its body
definite loop
Performs no actions in its body
loop control variable
Performs no actions in its body
binary operators
Performs no actions in its body
loop fusion
Performs no actions in its body
decrementing
Performs no actions in its body
for loop
Performs no actions in its body
sleep() method
Performs no actions in its body
empty body
Performs no actions in its body
do-nothing loop
Performs no actions in its body
*=
Performs no actions in its body
data validation
Performs no actions in its body
accumulating
Performs no actions in its body
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
52
Match between columns
Repeatedly increasing a value by an amount
prefix ++
Repeatedly increasing a value by an amount
block
Repeatedly increasing a value by an amount
definite loop
Repeatedly increasing a value by an amount
loop control variable
Repeatedly increasing a value by an amount
binary operators
Repeatedly increasing a value by an amount
loop fusion
Repeatedly increasing a value by an amount
decrementing
Repeatedly increasing a value by an amount
for loop
Repeatedly increasing a value by an amount
sleep() method
Repeatedly increasing a value by an amount
empty body
Repeatedly increasing a value by an amount
do-nothing loop
Repeatedly increasing a value by an amount
*=
Repeatedly increasing a value by an amount
data validation
Repeatedly increasing a value by an amount
accumulating
Repeatedly increasing a value by an amount
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
53
Match between columns
Multiply and assign
prefix ++
Multiply and assign
block
Multiply and assign
definite loop
Multiply and assign
loop control variable
Multiply and assign
binary operators
Multiply and assign
loop fusion
Multiply and assign
decrementing
Multiply and assign
for loop
Multiply and assign
sleep() method
Multiply and assign
empty body
Multiply and assign
do-nothing loop
Multiply and assign
*=
Multiply and assign
data validation
Multiply and assign
accumulating
Multiply and assign
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
54
What is the output of the following code:​ loopCount = 1;
While(loopCount < 3)
   System.out.println("Hello");
   loopCount = loopCount + 1;

A) No output
B) Hello Hello
C) Hello Hello
Hello
D) This is an infinite loop
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
55
Match between columns
A shortcut for incrementing and accumulating
prefix ++
A shortcut for incrementing and accumulating
block
A shortcut for incrementing and accumulating
definite loop
A shortcut for incrementing and accumulating
loop control variable
A shortcut for incrementing and accumulating
binary operators
A shortcut for incrementing and accumulating
loop fusion
A shortcut for incrementing and accumulating
decrementing
A shortcut for incrementing and accumulating
for loop
A shortcut for incrementing and accumulating
sleep() method
A shortcut for incrementing and accumulating
empty body
A shortcut for incrementing and accumulating
do-nothing loop
A shortcut for incrementing and accumulating
*=
A shortcut for incrementing and accumulating
data validation
A shortcut for incrementing and accumulating
accumulating
A shortcut for incrementing and accumulating
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
56
Match between columns
Ensuring that a value is in a range
prefix ++
Ensuring that a value is in a range
block
Ensuring that a value is in a range
definite loop
Ensuring that a value is in a range
loop control variable
Ensuring that a value is in a range
binary operators
Ensuring that a value is in a range
loop fusion
Ensuring that a value is in a range
decrementing
Ensuring that a value is in a range
for loop
Ensuring that a value is in a range
sleep() method
Ensuring that a value is in a range
empty body
Ensuring that a value is in a range
do-nothing loop
Ensuring that a value is in a range
*=
Ensuring that a value is in a range
data validation
Ensuring that a value is in a range
accumulating
Ensuring that a value is in a range
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
57
Match between columns
Subtracting 1 from a variable
prefix ++
Subtracting 1 from a variable
block
Subtracting 1 from a variable
definite loop
Subtracting 1 from a variable
loop control variable
Subtracting 1 from a variable
binary operators
Subtracting 1 from a variable
loop fusion
Subtracting 1 from a variable
decrementing
Subtracting 1 from a variable
for loop
Subtracting 1 from a variable
sleep() method
Subtracting 1 from a variable
empty body
Subtracting 1 from a variable
do-nothing loop
Subtracting 1 from a variable
*=
Subtracting 1 from a variable
data validation
Subtracting 1 from a variable
accumulating
Subtracting 1 from a variable
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
58
What kind of loop is this: response = keyboard.nextInt();
While (response == 1)
{
    System.out.print ("Enter 1 to continue; 0 to stop");
    response = keyboard.nextInt();
}

A) posttest
B) definite
C) event-driven
D) counted
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
59
Match between columns
The value that determines whether loop execution continues
prefix ++
The value that determines whether loop execution continues
block
The value that determines whether loop execution continues
definite loop
The value that determines whether loop execution continues
loop control variable
The value that determines whether loop execution continues
binary operators
The value that determines whether loop execution continues
loop fusion
The value that determines whether loop execution continues
decrementing
The value that determines whether loop execution continues
for loop
The value that determines whether loop execution continues
sleep() method
The value that determines whether loop execution continues
empty body
The value that determines whether loop execution continues
do-nothing loop
The value that determines whether loop execution continues
*=
The value that determines whether loop execution continues
data validation
The value that determines whether loop execution continues
accumulating
The value that determines whether loop execution continues
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
60
Match between columns
Multiple statements within curly braces
prefix ++
Multiple statements within curly braces
block
Multiple statements within curly braces
definite loop
Multiple statements within curly braces
loop control variable
Multiple statements within curly braces
binary operators
Multiple statements within curly braces
loop fusion
Multiple statements within curly braces
decrementing
Multiple statements within curly braces
for loop
Multiple statements within curly braces
sleep() method
Multiple statements within curly braces
empty body
Multiple statements within curly braces
do-nothing loop
Multiple statements within curly braces
*=
Multiple statements within curly braces
data validation
Multiple statements within curly braces
accumulating
Multiple statements within curly braces
% =
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
61
Why would a loop with altered user input be considered a type of indefinite loop? Give an example.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
62
What would happen if a semicolon is mistakenly placed at the end of a partial statement of a while loop with a Boolean expression and with an empty body?
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
63
Explain why an infinite loop might not actually execute infinitely.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
64
How could a programmer identify and escape from an infinite loop?
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
65

while(count < getNumberOfEmployees())
Examine the statement above. Write the code that will result in more efficient program execution assuming the result of getNumberOfEmployees() stays the same.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
66
How are indefinite loops used for validating data? Why is a loop structure typically the better choice for validating data than an if statement?
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
67
How does a for loop work?
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
68
Describe how a loop is controlled by a Boolean expression.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
69
Provide a code example of a pretest loop and an example of a posttest loop.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
70
What are some unconventional uses of the three sections inside the parentheses of a  for loop? Show at least three examples using code.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
71
What is loop fusion? Write a code segment that uses loop fusion to call two methods, method1 and method2 , 10 times each.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
72
counterLoop = 1;
while(counterLoop < 10);
{
     System.out.println("Hello");
     counterLoop = counterLoop + 1;
}
What is the problem in the above while loop? How would you correct the problem?
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
73
public class IncrDemo
{
    public static void main(String[] args)
    {
      int myVal, yourVal;
      myVal = 10;
      System.out.println("My initial value is " + myVal);
      yourVal = ++myVal;
      System.out.println("My new value is " + myVal);
      System.out.println("Your value is " + yourVal):
    }
}
Using the above code, describe how the three println output commands will appear. Explain the values stored in the variables during code execution.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
74
How are nested loops implemented in a loop structure?
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
75
while(10 > 1)
{
   System.out.println("This prints forever.");
}
Identify the problem that exists in the above while loop.
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
76
​What are the three sections inside the parentheses of a for loop typically used for?
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
77
How could you rewrite the following code to have the arithmetic performed only once, even if the loop executes 1,000 times?
while (x < a + b)
// loop body
Unlock Deck
Unlock for access to all 77 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 77 flashcards in this deck.