Unit 8 Assignment 1 HW
6. What is an infinite loop? Write the code for an infinite loop.
An infinite loop is a sequence of instructions in a computer program which loops endlessly.
Example of an infinite loop:
Set k = 1
While k < = 5
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.
3. // Declare a counter variable.
// 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
4. //Declare Integer number
Declare an accumulator variable
Declare Integer total = 0
Declare Integer counter
For counter = 1 to 10
Display “Enter a number.”
Set total = total + number
Display “The total is”, total
9. Declare Integer count
For count < 50
Display “The count is “, count
Set count = 1 To 50
10. //Declare integer count