CS110 Practice Quiz #7
for
statement
Choose the best alternative:
The
for
loop is called a
fixed repetition
loop because the loop is repeated a
fixed
number of times.
True
False
The loop counter in a
for
loop is altered
after
the loop statements are executed in a given iteration.
True
False
The
for
loop is known as a
post-test
loop.
True
False
In the
for
statement below,
i
is called a(n)
loop control variable
incrementer
.
for (int i = 1; i < 5; i++)
System.out.println('W');
The
for
loop will always execute at least once. (A
one-trip
loop.)
True
False
.
What output is produced by the segment of code shown below:
for (int i = 1; i < 5; i++)
System.out.println('A');
What output is produced by the segment of code shown below:
for (int i = 1; i <= 5; i++)
System.out.println('W');
The segment of code below will result in
AAA
an infinite loop
.
for (int i = 1; i <= 3;)
System.out.println('A');
What output is produced by the segment of code shown below:
for (int x = 3; x >= -1; x--)
System.out.println(x);
What output is produced by the segment of code shown below:
for (char c = 'a'; c <= 'd'; c++)
System.out.println(c);
The output produced by the segment of code shown below is
0123
nothing - the loop statements never execute.
.
for (int i = 0; i >= 3; i++ )
System.out.println(i);
What output is produced by the segment of code shown below:
for (int i = 1; i <= 10; i += 2)
System.out.println(i);
What output is produced by the segment of code shown below:
for (int i = 1; i <= 10; i ++)
{ System.out.println(i);
i++;
}
Answers
true
true
false. The for loop is a pre-test loop.
loop control variable
false. The for loop is a zero-trip loop. The do-while loop is a one-trip loop.
AAAA
WWWWW
An infinite loop.
3210-1
abcd
nothing - the loop statements never execute.
13579
13579 NOTE: The loop counter also incremented inside the loop.