Chapter 5. Repetition Structures

¡Supera tus tareas y exámenes ahora con Quizwiz!

5.19 . A program that calculates the total of a series of numbers typically has what two elements?

(1) A loop that reads each number in the series, and (2) a variable that accumulates the total of the numbers as they are read.

5.15. Look at the following pseudocode. If it were a real program, what would it display? Declare Integer counter For counter = 0 to 500 Step 100 Display counter End For

0 100 200 300 400 500

5.14. Look at the fallowing pseudocode.If it were real program, what would it display? Declare Integer counter For counter = 1 to 5 Display counter End For

1 2 3 4 5

5.16. Look at the following pseudocode. If it were a real program, what would it display? Declare Integer counter = 1 Constant Integer MAX = 8 While counter 《= MAX Display counter Set counter = counter + 1 End While

1 2 3 4 5 6 7 8

5.17. Look at the following pseudocode.If it were a real program, what would it display? Declare Integer counter = 1 Constant Integer MAX = 7 While counter 《= MAX Display counter Set counter = counter + 2 End While

1 3 5 7

5.22. Look at the following pseudocode. If it were a real program, what would it display? Declare Integer number1 = 10, number2 = 5 Set number1 = number1 + number2 Display number 1 Display number 2

15 5

5.23. Look at the following pseudocode.If it were a real program, what would it display? Declare Integer counter? total = 0 For counter = 1 to 5 Set total = total + counter Enf For Display total

5

5.18. Look at the following pseudocode.If it were a real program, what would it display? Declare Integer counter Constant Integer MIN = 1 For counter = 5 to MIN step - 1 Display counter End For

5 4 3 2 1

5.13. Look at the following pseudocode. If it were a real program, what would it display? Declare Integer number = 5 Set number = number + 1 Display number

6

5.9. What is the difference between a Do-While loop and a Do-Untill loop?

A Do-While loop iterates while a condition is true. When the condition is false, the Do-While loop stops. A Do-Untill loop iterates until a condition is true. When the condition is true, the Do-Untill loop stops.

5.8. What is infinity loop?

A loop that has no way of stopping, and repeats until the program is interrupted.

5.3. What is a count-controlled loop?

A loop that repeats a spesific number of times.

5.2. What is a condition-controlled loop?

A loop that uses a true/false condition to control the number of times that it repeats.

5.5. What is the difference between a pretest loop and a posttest loop?

A pretest tests its condition before it performs an iteration. A posttest loop tests its condition after it performs an iteration.

2.25. Whatvis sentinel?

A sentinel is a special value that marks the end of a list of items.

5.24. Why should you take care to choose a unique value as a sentinel?

A sentinel value must be unique enough that it will not be mistaken as a regular value in the list.

5.1. What is a repetition structure?

A structure that causes a section of code to repeat.

5.20. What is an accumulator?

A variable that is used to accumulate the total of a series of numbers.

5.10. What is a counter variable?

A variable that is used to store the number of iretations that it has performed.

5.7. Does the Do-While loop test its condition before or after it performs an iteration?

After

5.4. What is a loop iteration?

An execution of the statement in the body of the loop.

5.6. Does the While loop test its condition before or aftet it performs an iteration?

Before

5.12. When you increment a variable, what are you doing?

Incrementing a variable means increasing its value. Decremenating a variable means decreasing its value.

5.11. What three actions do count-controlled loops typically perform using the counter variable?

Initialization, test, and increment

5.21. Should an accumulator be initialized to any specific value? Why or why not?

Yes, it should be initialized with the value 0. This is because values are added to the accumulator by a loop. If the accumulator does not start at the value 0, it will not contain the correct tottal of the numbers that were added to it whe the loop ends.


Conjuntos de estudio relacionados

PassPoint: Antepartum Period ML8

View Set

TSU ECON 201 Exam 3 Chapters 6-8

View Set

Business Statistics Chapter 7 Smartbook

View Set

Environmental Econ Concept Quiz 3

View Set

Anatomy and physiology chapter 4

View Set