Premium Essay

Pt1420 Unit8

In:

Submitted By fishingladyla310
Words 665
Pages 3
Unit 8 Assignment 1: Homework
Short Answer Review Questions 6-10

6. What is an infinite loop? Write the code for an infinite loop.
An infinite loop (or endless loop) is a sequence of instructions in a computer program which loops endlessly, either due to the loop having no terminating condition, having one that can never be met, or one that causes the loop to start over. while (true)
{
// do stuff
}
to break it: while (true)
{
if (condition) break;
}

OR
Set k = 1
While k < = 5
Display k
End While

7. A For loop looks like what other loop in a flowchart?
A For loop looks like a count-controlled loop.

8. Why is it critical that accumulator variables are properly initialized?
An accumulator is used to keep a running total of numbers. In a loop, a value is usually added to the current value of the accumulator. If it is not properly initialized, it will not contain the correct total.

9. What is the advantage of using a sentinel?
The advantage of using a sentinel is that when you are processing a long list of values with a loop a sentinel marks the end of a list of items. There is no limit to how many times a loop can execute

10. Why must the value chosen for use as a sentinel be carefully selected?
The value of a sentinel needs to be carefully selected because it can’t be mistaken as a regular value in the list

Algorithm Workbench Review Questions 3, 4, 9, 10

3. Design a For loop that displays the following set of numbers: 0, 10, 20, 30, 40, 50 . . . 1000
// Declare a counter variable.
Declare Integer

// Constant for the maximum value
Constant Integer MAX_VALUE = 100

//Display the multiples of 10 from 0 through 100
For counter = 0 to MAX_VALUE
Display counter
End For

4. Design a loop that asks the user to enter a number. The loop should iterate 10 times and keep a running total

Similar Documents