Deck 6: Looping

Full screen (f)
exit full mode
Question
An indefinite loop is a(n) ____ loop.

A) counter-controlled
B) event-controlled
C) initialized
D) validating
Use Space or
up arrow
down arrow
to flip the card.
Question
When nesting loops, the variable in the outer loop changes more frequently.
Question
A loop controlled by the user is a type of ____ loop.

A) indefinite
B) definite
C) counter-controlled
D) incrementing
Question
Which is an infinite loop?

A) loopCount = 5; while(loopCount > 3);
{
System.out.println("Hello");
LoopCount = loopCount - 1;
}
B) loopCount = 1; while(loopCount
{
System.out.println("Hello");
}
C) loopCount = 4; while(loopCount
{
System.out.println("Hello");
LoopCount = loopCount + 1;
}
D) loopCount = 1; while(loopCount
{
System.out.println("Hello");
LoopCount = loopCount + 1;
}
Question
A statement that will alter the value of the loop control variable is included in the body of a loop.
Question
A loop that never ends is called a(n) ____ loop.

A) definite
B) infinite
C) while
D) for
Question
____ is the process of ensuring that a value falls within a specified range.

A) Value checking
B) Data integrity
C) Validating data
D) A range check
Question
In order to improve loop performance, it's important to make sure the loop does not include unnecessary operations or statements.
Question
Shortcut operators are a programmer's only choice when incrementing or accumulating a variable's value.
Question
Making a comparison to 0 is slower than making a comparison to any other value.
Question
Altering a variable within both a for statement and within the block it controls can produce errors that are difficult to find.
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
On many keyboards, the Break key is also the ____ key.

A) Pause
B) Esc
C) Delete
D) Ctrl
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
The statements that make up a loop body will continue to execute as long as the expression value remains false.
Question
It is important that the loop control ____ be altered within the body of the loop.

A) value
B) variable
C) constant
D) argument
Question
Programmers rarely use indefinite loops when validating input data.
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
A ____ is a structure that allows repeated execution of a block of statements.

A) body
B) Boolean expression
C) loop
D) loop control
Question
Many seasoned programmers start counter values at 1 because they are used to doing so when working with arrays.
Question
How many times will outputLabel be called? for(customer = 1; customer
     for(color = 1; color
          outputLabel();

A) 0
B) 3
C) 20
D) 60
Question
As long as methods do not depend on one another, ____ 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
A(n) ____________________ is a body with no statements in it.
Question
If a(n) ____________________ is altered both within the for statement and within the block it controls, it can be very difficult to follow the program's logic.
Question
A for loop provides a convenient way to create a(n) ____ loop.

A) counter-controlled
B) posttest
C) while
D) infinite
Question
When loops are nested, each pair contains a(n) ____________________ loop and an outer loop.
Question
The ____________________ loop is the posttest loop used in Java.
Question
You use a unary minus sign preceding a value to make the value ____.

A) negative
B) positive
C) valid
D) constant
Question
The process of repeatedly increasing a value by some amount is known as ____.

A) checking
B) adding
C) accumulating
D) containing
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
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
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
The order of the conditional expressions in the following is most important within a(n) ____ loop.   while(requestedNum > LIMIT || requestedNum

A) nested
B) posttest
C) pretest
D) indefinite
Question
One execution of any loop is called a(n) ____________________.
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
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
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) 8
B) 7
C) 9
D) 10
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
Match between columns
Operate on two values
block
Operate on two values
loop control variable
Operate on two values
decrementing
Operate on two values
definite loop
Operate on two values
prefix ++
Operate on two values
binary operators
Operate on two values
for loop
Operate on two values
sleep() method
Operate on two values
loop fusion
The technique of combining two loops into one
block
The technique of combining two loops into one
loop control variable
The technique of combining two loops into one
decrementing
The technique of combining two loops into one
definite loop
The technique of combining two loops into one
prefix ++
The technique of combining two loops into one
binary operators
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
loop fusion
Part of the Thread class in the java.lang package
block
Part of the Thread class in the java.lang package
loop control variable
Part of the Thread class in the java.lang package
decrementing
Part of the Thread class in the java.lang package
definite loop
Part of the Thread class in the java.lang package
prefix ++
Part of the Thread class in the java.lang package
binary operators
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
loop fusion
The value that determines whether loop execution continues
block
The value that determines whether loop execution continues
loop control variable
The value that determines whether loop execution continues
decrementing
The value that determines whether loop execution continues
definite loop
The value that determines whether loop execution continues
prefix ++
The value that determines whether loop execution continues
binary operators
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
loop fusion
Multiple statements within curly braces
block
Multiple statements within curly braces
loop control variable
Multiple statements within curly braces
decrementing
Multiple statements within curly braces
definite loop
Multiple statements within curly braces
prefix ++
Multiple statements within curly braces
binary operators
Multiple statements within curly braces
for loop
Multiple statements within curly braces
sleep() method
Multiple statements within curly braces
loop fusion
Within parentheses are three sections separated by exactly two semicolons
block
Within parentheses are three sections separated by exactly two semicolons
loop control variable
Within parentheses are three sections separated by exactly two semicolons
decrementing
Within parentheses are three sections separated by exactly two semicolons
definite loop
Within parentheses are three sections separated by exactly two semicolons
prefix ++
Within parentheses are three sections separated by exactly two semicolons
binary operators
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
loop fusion
A shortcut for incrementing and accumulating
block
A shortcut for incrementing and accumulating
loop control variable
A shortcut for incrementing and accumulating
decrementing
A shortcut for incrementing and accumulating
definite loop
A shortcut for incrementing and accumulating
prefix ++
A shortcut for incrementing and accumulating
binary operators
A shortcut for incrementing and accumulating
for loop
A shortcut for incrementing and accumulating
sleep() method
A shortcut for incrementing and accumulating
loop fusion
A countered loop
block
A countered loop
loop control variable
A countered loop
decrementing
A countered loop
definite loop
A countered loop
prefix ++
A countered loop
binary operators
A countered loop
for loop
A countered loop
sleep() method
A countered loop
loop fusion
Subtracting 1 from a variable
block
Subtracting 1 from a variable
loop control variable
Subtracting 1 from a variable
decrementing
Subtracting 1 from a variable
definite loop
Subtracting 1 from a variable
prefix ++
Subtracting 1 from a variable
binary operators
Subtracting 1 from a variable
for loop
Subtracting 1 from a variable
sleep() method
Subtracting 1 from a variable
loop fusion
Question
Create an indefinite while loop that will validate that the loop control variable named userNum is less than the constant MAXVALUE . While true, create a println statement to output "Please enter a higher value". Get user input of another value for userNum after each println statement. Once MAXVALUE is reached, create a final println statement that will output "Max value reached".
Question
What are some of the shortcuts Java provides programmers for incrementing and accumulating? Give examples of statements.
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
// loop body
Question
How does a for loop work?
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
counterLoop = 1;
while(counterLoop
{
     System.out.println("Hello");
     counterLoop = counterLoop + 1;
}
What is the problem in the above while loop? How would you correct the problem?
Question
Describe how a loop is controlled by a Boolean expression.
Question
Why would a loop with altered user input be considered a type of indefinite loop? Give an example.
Question
Provide a code example of a pretest loop and an example of a posttest loop.
Question
How could a programmer identify and escape from an infinite loop?
Question
What is loop fusion? Write a code segment that uses loop fusion to call two methods, method1 and method2 , 10 times each.
Question
  Using the flowchart and code above, describe the execution of the loop. Identify the loop control variable and the value of the variable as the code is executed.<div style=padding-top: 35px>
Using the flowchart and code above, describe the execution of the loop. Identify the loop control variable and the value of the variable as the code is executed.
Question
Why would a programmer use curly braces in the body of a do…while 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
Write a definite while loop that initializes a loop control variable named decreaseOne to 10 and continues while  decreaseOne > 0. Decrement the loop control variable by 1 and include the println output "Keep going" within the loop.
Question
Describe a counter-controlled loop. Explain the process of incrementing and decrementing, and explain the best method for executing a loop a specific number of times.
Question
What are the three sections inside the parentheses of a for loop typically used for?
Question
Explain why an infinite loop might not actually execute infinitely.
Question
How are nested loops implemented in a loop structure?
Question
while(count
Examine the statement above. Write the code that will result in more efficient program execution assuming the result of getNumberOfEmployees() stays the same.
Question
while(10 > 1)
{
   System.out.println("This prints forever.");
}
Identify the problem that exists in the above while loop.
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 indefinite loops used for validating data? Why is a loop structure typically the better choice for validating data than an if statement?
Question
  Using the information provided above, write the while loop that will correctly follow the execution of the flowchart.<div style=padding-top: 35px>
Using the information provided above, write the while loop that will correctly follow the execution of the flowchart.
Question
public class DoWhileExample
{
    public static void main(String[] args)
    {
int currentValue;
____
____
____
____
____
    }
}
Complete the code above by writing a do…while posttest loop that will output the value of the variable currentValue in a println statement. After the output statement, add a decrement statement to decrease the value of currentValue by 1. Continue the loop until currentValue is equal to 0.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/66
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 6: Looping
1
An indefinite loop is a(n) ____ loop.

A) counter-controlled
B) event-controlled
C) initialized
D) validating
B
2
When nesting loops, the variable in the outer loop changes more frequently.
False
3
A loop controlled by the user is a type of ____ loop.

A) indefinite
B) definite
C) counter-controlled
D) incrementing
A
4
Which is an infinite loop?

A) loopCount = 5; while(loopCount > 3);
{
System.out.println("Hello");
LoopCount = loopCount - 1;
}
B) loopCount = 1; while(loopCount
{
System.out.println("Hello");
}
C) loopCount = 4; while(loopCount
{
System.out.println("Hello");
LoopCount = loopCount + 1;
}
D) loopCount = 1; while(loopCount
{
System.out.println("Hello");
LoopCount = loopCount + 1;
}
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
5
A statement that will alter the value of the loop control variable is included in the body of a loop.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
6
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 66 flashcards in this deck.
Unlock Deck
k this deck
7
____ is the process of ensuring that a value falls within a specified range.

A) Value checking
B) Data integrity
C) Validating data
D) A range check
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
8
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 66 flashcards in this deck.
Unlock Deck
k this deck
9
Shortcut operators are a programmer's only choice when incrementing or accumulating a variable's value.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
10
Making a comparison to 0 is slower than making a comparison to any other value.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
11
Altering a variable within both a for statement and within the block it controls can produce errors that are difficult to find.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
12
Before entering a loop, the first input statement, or ____, is retrieved.

A) empty body
B) posttest loop
C) loop body
D) priming read
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
13
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 66 flashcards in this deck.
Unlock Deck
k this deck
14
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 66 flashcards in this deck.
Unlock Deck
k this deck
15
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 66 flashcards in this deck.
Unlock Deck
k this deck
16
It is important that the loop control ____ be altered within the body of the loop.

A) value
B) variable
C) constant
D) argument
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
17
Programmers rarely use indefinite loops when validating input data.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
18
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 66 flashcards in this deck.
Unlock Deck
k this deck
19
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 66 flashcards in this deck.
Unlock Deck
k this deck
20
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 66 flashcards in this deck.
Unlock Deck
k this deck
21
How many times will outputLabel be called? for(customer = 1; customer
     for(color = 1; color
          outputLabel();

A) 0
B) 3
C) 20
D) 60
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
22
As long as methods do not depend on one another, ____ 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 66 flashcards in this deck.
Unlock Deck
k this deck
23
A(n) ____________________ is a body with no statements in it.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
24
If a(n) ____________________ is altered both within the for statement and within the block it controls, it can be very difficult to follow the program's logic.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
25
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 66 flashcards in this deck.
Unlock Deck
k this deck
26
When loops are nested, each pair contains a(n) ____________________ loop and an outer loop.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
27
The ____________________ loop is the posttest loop used in Java.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
28
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 66 flashcards in this deck.
Unlock Deck
k this deck
29
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 66 flashcards in this deck.
Unlock Deck
k this deck
30
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 66 flashcards in this deck.
Unlock Deck
k this deck
31
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 66 flashcards in this deck.
Unlock Deck
k this deck
32
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 66 flashcards in this deck.
Unlock Deck
k this deck
33
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 66 flashcards in this deck.
Unlock Deck
k this deck
34
The order of the conditional expressions in the following is most important within a(n) ____ loop.   while(requestedNum > LIMIT || requestedNum

A) nested
B) posttest
C) pretest
D) indefinite
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
35
One execution of any loop is called a(n) ____________________.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
36
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 66 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 66 flashcards in this deck.
Unlock Deck
k this deck
38
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 66 flashcards in this deck.
Unlock Deck
k this deck
39
In the expressions b = 8 and c = --b , what value will be assigned to the variable c ?

A) 8
B) 7
C) 9
D) 10
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
40
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 66 flashcards in this deck.
Unlock Deck
k this deck
41
Match between columns
Operate on two values
block
Operate on two values
loop control variable
Operate on two values
decrementing
Operate on two values
definite loop
Operate on two values
prefix ++
Operate on two values
binary operators
Operate on two values
for loop
Operate on two values
sleep() method
Operate on two values
loop fusion
The technique of combining two loops into one
block
The technique of combining two loops into one
loop control variable
The technique of combining two loops into one
decrementing
The technique of combining two loops into one
definite loop
The technique of combining two loops into one
prefix ++
The technique of combining two loops into one
binary operators
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
loop fusion
Part of the Thread class in the java.lang package
block
Part of the Thread class in the java.lang package
loop control variable
Part of the Thread class in the java.lang package
decrementing
Part of the Thread class in the java.lang package
definite loop
Part of the Thread class in the java.lang package
prefix ++
Part of the Thread class in the java.lang package
binary operators
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
loop fusion
The value that determines whether loop execution continues
block
The value that determines whether loop execution continues
loop control variable
The value that determines whether loop execution continues
decrementing
The value that determines whether loop execution continues
definite loop
The value that determines whether loop execution continues
prefix ++
The value that determines whether loop execution continues
binary operators
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
loop fusion
Multiple statements within curly braces
block
Multiple statements within curly braces
loop control variable
Multiple statements within curly braces
decrementing
Multiple statements within curly braces
definite loop
Multiple statements within curly braces
prefix ++
Multiple statements within curly braces
binary operators
Multiple statements within curly braces
for loop
Multiple statements within curly braces
sleep() method
Multiple statements within curly braces
loop fusion
Within parentheses are three sections separated by exactly two semicolons
block
Within parentheses are three sections separated by exactly two semicolons
loop control variable
Within parentheses are three sections separated by exactly two semicolons
decrementing
Within parentheses are three sections separated by exactly two semicolons
definite loop
Within parentheses are three sections separated by exactly two semicolons
prefix ++
Within parentheses are three sections separated by exactly two semicolons
binary operators
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
loop fusion
A shortcut for incrementing and accumulating
block
A shortcut for incrementing and accumulating
loop control variable
A shortcut for incrementing and accumulating
decrementing
A shortcut for incrementing and accumulating
definite loop
A shortcut for incrementing and accumulating
prefix ++
A shortcut for incrementing and accumulating
binary operators
A shortcut for incrementing and accumulating
for loop
A shortcut for incrementing and accumulating
sleep() method
A shortcut for incrementing and accumulating
loop fusion
A countered loop
block
A countered loop
loop control variable
A countered loop
decrementing
A countered loop
definite loop
A countered loop
prefix ++
A countered loop
binary operators
A countered loop
for loop
A countered loop
sleep() method
A countered loop
loop fusion
Subtracting 1 from a variable
block
Subtracting 1 from a variable
loop control variable
Subtracting 1 from a variable
decrementing
Subtracting 1 from a variable
definite loop
Subtracting 1 from a variable
prefix ++
Subtracting 1 from a variable
binary operators
Subtracting 1 from a variable
for loop
Subtracting 1 from a variable
sleep() method
Subtracting 1 from a variable
loop fusion
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
42
Create an indefinite while loop that will validate that the loop control variable named userNum is less than the constant MAXVALUE . While true, create a println statement to output "Please enter a higher value". Get user input of another value for userNum after each println statement. Once MAXVALUE is reached, create a final println statement that will output "Max value reached".
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
43
What are some of the shortcuts Java provides programmers for incrementing and accumulating? Give examples of statements.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
44
How could you rewrite the following code to have the arithmetic performed only once, even if the loop executes 1,000 times?
while (x
// loop body
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
45
How does a for loop work?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
46
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 66 flashcards in this deck.
Unlock Deck
k this deck
47
counterLoop = 1;
while(counterLoop
{
     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 66 flashcards in this deck.
Unlock Deck
k this deck
48
Describe how a loop is controlled by a Boolean expression.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
49
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 66 flashcards in this deck.
Unlock Deck
k this deck
50
Provide a code example of a pretest loop and an example of a posttest loop.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
51
How could a programmer identify and escape from an infinite loop?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
52
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 66 flashcards in this deck.
Unlock Deck
k this deck
53
  Using the flowchart and code above, describe the execution of the loop. Identify the loop control variable and the value of the variable as the code is executed.
Using the flowchart and code above, describe the execution of the loop. Identify the loop control variable and the value of the variable as the code is executed.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
54
Why would a programmer use curly braces in the body of a do…while loop?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
55
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 66 flashcards in this deck.
Unlock Deck
k this deck
56
Write a definite while loop that initializes a loop control variable named decreaseOne to 10 and continues while  decreaseOne > 0. Decrement the loop control variable by 1 and include the println output "Keep going" within the loop.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
57
Describe a counter-controlled loop. Explain the process of incrementing and decrementing, and explain the best method for executing a loop a specific number of times.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
58
What are the three sections inside the parentheses of a for loop typically used for?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
59
Explain why an infinite loop might not actually execute infinitely.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
60
How are nested loops implemented in a loop structure?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
61
while(count
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 66 flashcards in this deck.
Unlock Deck
k this deck
62
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 66 flashcards in this deck.
Unlock Deck
k this deck
63
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 66 flashcards in this deck.
Unlock Deck
k this deck
64
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 66 flashcards in this deck.
Unlock Deck
k this deck
65
  Using the information provided above, write the while loop that will correctly follow the execution of the flowchart.
Using the information provided above, write the while loop that will correctly follow the execution of the flowchart.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
66
public class DoWhileExample
{
    public static void main(String[] args)
    {
int currentValue;
____
____
____
____
____
    }
}
Complete the code above by writing a do…while posttest loop that will output the value of the variable currentValue in a println statement. After the output statement, add a decrement statement to decrease the value of currentValue by 1. Continue the loop until currentValue is equal to 0.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 66 flashcards in this deck.