Chapter 5- Looping-The loop control variable is initialized

| August 31, 2017

Question
Chapter 5: Looping

TRUE/FALSE

1. The loop control variable is initialized after entering the loop.

2. In some cases, a loop control variable does not have to be initialized.

3. An indefinite loop is a loop that never stops.

4. You can either increment or decrement the loop control variable.

5. When one loop appears inside another is is called an indented loop.

6. Forgetting to initialize and alter the loop control variable is a common mistake that programmers sometimes make.

7. Every high-level computer programming language contains a while statement.

8. Both the while loop and the for loop are examples of pretest loops.

9. The safest action is to assign the value 1 to accumulators before using them.

10. It is the programmer’s responsibility to initialize all variables that must start with a specific value.

MULTIPLE CHOICE

1. 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

2. Once your logic enters the body of a structured loop, ____.

a. the entire loop must execute

b. the loop can be terminated with a break statement

c. the loop will execute indefinitely

d. a decision statement will be evaluated

3. The last step in a while loop is usually 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

4. A(n) ____ loop executes a predetermined number of times.

a. terminal c. indefinite

b. definite d. infinite

5. Many loop control variable values are altered by ____, or adding to them.

a. incrementing c. accumulating

b. decrementing d. deprecating

6. A(n) ____ is any numeric variable you use to count the number of times an event has occurred.

a. accumulator c. index

b. key d. counter

7. A loop within another loop is known as a(n) ____ loop.

a. indefinite c. nested

b. infinite d. hidden

8. When one loop appears inside another, the loop that contains the other loop is called the ____ loop.

a. indefinite c. inner

b. definite d. outer

9. Usually, when you create nested loops, each loop has its own ____.

a. sentinel value c. entrance condition

b. goto statement d. loop control variable

10. 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

11. A mistake programmers often make with loops is that they ____.

a. neglect to initialize the loop control variable prior to entering the loop body

b. increment the loop control variable inside of the loop body

c. validate data to ensure values are the correct data type or that they fall within an acceptable range

d. enclose the inner loop entirely within the outer loop in a nested loop

12. A comparison is correct only when the correct ____ and operator are used.

a. expression c. statements

b. operands d. index

13. Programmers use the term ____ to describe programs that are well designed and easy to understand and maintain.

a. industrial c. well behaved

b. intractable d. elegant

14. You usually use the for loop with ____ loops.

a. indefinite c. inner

b. definite d. outer

15. The ____ loop provides three actions in one compact statement.

a. for c. do until

b. while d. repeat

16. The amount by which a for loop control variable changes is often called a ____ value.

a. group c. step

b. key d. sentinel

17. In a ____, the loop body might never execute because the question controlling the loop might be false the first time it is asked.

a. summary report c. posttest loop

b. pretest loop d. loop control

18. In a ____, the loop body executes at least one time because the loop control variable is not tested until after one iteration.

a. stub c. posttest loop

b. pretest loop d. loop control

19. The ____ loop is particularly useful when processing arrays.

a. for c. infinite

b. while d. nested

20. A(n) ____ is very similar to a counter that you use to count loop iterations, except that you usually add a value other than one to this type of variable.

a. transaction c. validator

b. total d. accumulator

21. ____ is a technique with which you try to prepare for all possible errors before they occur.

a. Incrementing c. Nested loop

b. Stub d. Defensive programming

22. Business reports that list only totals, with no individual item details, are called ____.

a. detail reports c. transaction reports

b. summary reports d. control-break reports

23. Loops are frequently used to ____; that is, to make sure it is meaningful and useful.

a. validate data c. simulate data

b. restructure data d. corroborate data

24. Programmers employ the acronym ____ to mean that if your input is incorrect, your output is worthless.

a. IOW c. IOCW

b. GIGO d. GIGS

25. ____ a data item means you override incorrect data by setting the variable to a specific value.

a. Flexing c. Forcing

b. Tracing d. Blanking

COMPLETION

1. Adding to a variable is called ____________________ the variable.

2. When one loop appears inside another, the loop that is contained is called the ____________________ loop.

3. In a for statement, a loop control variable is initialized, evaluated, and ____________________.

4. ____________________ are frequently used to accumulate totals and to validate data.

5. Making sure data falls within an acceptable range is referred to as ____________________ the data.

MATCHING

Match each term with a statement below.

a. indefinite f. decrement

b. loop control variable g. accumulator

c. nested loops h. loop

d. counter i. sentinel value

e. increment j. stub

1. One set of instructions that operates on multiple, separate sets of data

2. Initialized before entering a while loop

3. To add to a variable

4. To decrease a variable’s value

5. Any numeric variable you use to count the number of times an event has occurred

6. A loop that may execute a different number of times each time the program executes

7. A value such as Y or N that stops a loop

8. Loops within loops

9. An empty module that acts as a placeholder

10. A variable that you use to gather values

SHORT ANSWER

1. What is an advantage of using fewer instructions?

2. What are the three steps that should occur in every loop?

3. What is the difference between a definite loop and an indefinite loop?

4. Explain when it would be appropriate to write an indefinite loop.

5. What are common mistakes made by programmers in coding loops?

6. What are the tasks performed by the for count = 0 to 3 statement?

7. What is a step value?

8. When are you required to use a for statement, and what are the advantages of for statements?

9. What is an accumulator?

10. How might user data be validated?

Get a 30 % discount on an order above $ 5
Use the following coupon code:
CHRISTMAS
Order your essay today and save 30% with the discount code: CHRISTMASOrder Now
Positive SSL