The loop control variable is initialized after entering the loop.
True
False - Answers False
You can either increment or decrement the loop control variable.
True
False - Answers True
An indefinite loop is a loop that never stops.
True
False - Answers False
Forgetting to initialize and alter the loop control variable are common mistakes that programmers
sometimes make.
True
False - Answers True
Both the while loop and the for loop are examples of pretest loops.
True
False - Answers True
The first step in a while loop is typically to ____.
A. compare the loop control variable to a constant value
B. initialize the loop control variable
C. increment the loop control variable
D. execute the body of the loop - Answers B
A(n) ____ is any numeric variable you use to count the number of times an event has occurred.
accumulator
key
index
counter - Answers counter
A loop within another loop is known as a(n) ____ loop.
indefinite
infinite
nested
hidden - Answers nested
A mistake programmers often make with loops is that they ____.
A. initialize the loop control variable prior to entering the loop body
B. increment the loop control variable inside of the loop body
C. include statements inside the loop that belong outside the loop
D. enclose the inner loop entirely within the outer loop in a nested loop - Answers C
What are the values of i and j after the following code fragment runs?int i = 60;
int j = 50;
int count = 0;
while (count < 5)
{i = i + i;i = i + 1;j = j - 1;j = j - j;count++;}
System.out.println("i=" + i + ", j=" + j);
A. i = 1951, j = 0
B. i = 1951, j = 45
C. i = 65, j = 1
D. i = 65, j = 45 - Answers A
Which error type does the "off-by-one" error belong to?
A. syntax error
B. compile-time error
C. run-time error
D. infinite loop - Answers C
What values does counter variable i take on when this loop executes?
for (int i = 20; i >= 2; i = i - 6)
{System.out.print(i + ",");}