Visual C# 2012 An introduction to object-oriented programming Joyce Farrell 5th
ID: 3776963 • Letter: V
Question
Visual C# 2012
An introduction to object-oriented programming
Joyce Farrell
5th edition
Chapter 5 Review Questions
1. A structure that allows repeated execution of a block of statements is a(n) _____________.
a) sequence b) selection c) loop d) array
2. The body of a while loo can consist of ___________.
a) a single statement
b) a block of statements within curly braces
c) either a or b
d) neither a nor b
3. A loop that never ends is called a(n)___________loop.
a) while b) for c) counted d) infinite
4. Which of the following is not required of a loop control variable in a correctly working loop?
a) It is reset to its initial value before the loop ends.
b) It is initialized before the loop starts
c) It is tested
d) It is altered in the loop body
5. A while loop with an empty body contains no ____________.
a) loop control variable
b) statements
c) curly braces
d) test within the parentheses of the while statement
6. A loop for which you do not know the number if iterations when you write it is a(n) _____________
a) definite loop b) indefinite loop c) counted loop d) for loop
7. What is the major advantage of using a for loop instead of a while loop?
a) With a for loop, it is impossible to create an infinite loop.
b) It is the only way to achieve an indefinite loop
c) Unlike with a while loop, the execution of multiple statements can depend on the test condition
d) The loop control variable is initialized, tested, and altered all in one place
8. A for loop statement must contain ______________.
a) two semicolons b) three commas c) four dots d) five pipes
9. In a for statement, the section before the first semicolon executes _______________.
a) once
b) once prior to each loop iteration
c) once after each loop iteration
d) one less time than the initial loop control variable value
10. The three sections of the for loop are most commonly used for _____________ the loop control variable
a) testing, outputting, and incrementing
b) initializing, testing, and incrementing
c) incrementing, selecting, and testing
d) initializing, converting, and outputting
11. Which loop is most convenient to use if the loop body must always execute at least once?
a) a do loop
b) a while loop
c) a for loop
d) an if loop
12. The loop control variable is checked at the bottom of which kind of loop?
a) a while loop
b) a do loop
c) a for loop
d) an if loop
13. A for loop is an example of a(n) ______________ loop.
a) untested b)pretest c) posttest d) infinite
14. A while loop is an example of a(n) _____________ loop.
a) untested b) pretest c) posttest d) infinite
15. When a loop is placed within another loop, the loops are said to be ____________.
a) infinite
b) bubbled
c) nested
d) overlapping
16. What does the following code segment display?
a = 1
while (a < 5);
{
a) 1234
b) 1
c) 4
d) nothing
17. What is the output of the following code segment?
s = 1;
while (s < 4)
++s;
Console.Write("{0}",s);
a) 1
b)4
c) 1234
d) 234
18. What is the output of the following code segment?
j = 5
while(j > 0)
{
Console.Write("{0} ", j);
j--;
a) 0
b) 5
c) 5 4 3 2 1
d) 5 4 3 2 1 0
19. What does the following code segment display?
for(f = 0; f < 3; ++f);
Console.Write("{0} ", f);
a) 0
b) 0 1 2
c) 3
d) nothing
20. What does the following code segment display?
for(t = 0; t < 3; ++t)
Console.Write("{0} ", t);
a) 0
b) 0 1
c) 0 1 2
d) 0 1 2 3
Explanation / Answer
1. c) loop.
2. c) either a or b
3. d) infinite.
4. a) It is reset to its initial value before the loop ends.
5. b) statements
6. c) counted loop.
7. d) The loop control variable is initialized, tested, and altered all in one place.
8. a) two semicolons.
9. a) once.
10. b) initializing, testing, and incrementing.
11. b) a do loop .
12. b) a do loop.
13. c) posttest.
14. b) pretest.
15. c) nested
16. a) 1234
17. b)4.
18. c) 5 4 3 2 1
19. c) 3
20. c) 0 1 2
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.