Control Structures Quiz


Identification:

Last Name:     

First Name:    

Class Section: 

Matching Part 1

Type the letter of the term which best matches the following descriptions:

Terms
a) init expression b) loop condition = false c) loop condition
d) body of loop e) for loop f) do loop
g) while loop h) curley braces i) loop expression

Descriptions
1. Code to repeat 2. Body of loop always executed at least one time 3. Used if body contains more than one program statement
4. Executed after the body of loop 5. Executed first 6. Repeat loop as long as this is TRUE
7.Terminates loop 8. Can be rewritten as for loop 9. Uses init expression, loop condition and loop expression

Matching Part 2

Type the letter of the term which best matches the following descriptions:

Terms
a)Boolean Expression b){ } c)If Else If Else
d)Switch e)If f)If Else

Descriptions
10.Used in 3-way decision 11.Code to execute is based on the value of a constant expression 12.Is either True or False
13.Either execute or skip code based on value of one expression 14.Needed if there is more than one statement to execute 15.Used in a 2-way decision

Put the letter of the best answer for the following:

16. Which order is correct for a for loop:

a. loop condition, init expression, body of loop, loop expression
b. init expression, body of loop, loop condition, loop expression
c. init expression, loop condition, body of loop, loop expression
d. loop condition, loop expression, body of loop, init expression
e. none of the above.
Answer:  

17. A for loop can be rewritten as a while loop:

a. always
b. when speed is a concern
c. never
Answer:  

18. A while loop can be rewritten as a do loop:

a. always
b. when speed is a concern
c. never
Answer:  

19. A while loop can be rewritten as a for loop:

a. always
b. when speed is a concern 
c. never
Answer:  

20. Which order is correct for a do loop:

a. boolean expression, body of loop
b. body of loop, boolean expression
c. init expression, body of loop
d. init expression, boolean expression, body of loop
e. none of the above
Answer:  

21. An if statement is used:

a. to repeat a portion of code
b. to either execute or skip a portion of code
c. to either execute or repeat a portion of code
d. none of the above
Answer:  

22. An if else construct is used:

a. to either execute or skip a portion of code
b. to repeat certain protions of code
c. to execute either one portion of code or another.
d. none of the above
Answer:  

23. A switch is used:

a. when execution needs to switch from one portion of the program to
another. 
b. when there is a choice of several possible portions of
code to execute, depending on the value of a boolean expression.
c. when there is a choice of several possible portions of
code to execute, depending on the value of a constant expression.
d. none of the above.
Answer: