pt1420 unit 8

pt1420 unit 8

  • Submitted By: cody88
  • Date Submitted: 11/10/2015 9:57 AM
  • Category: Technology
  • Words: 307
  • Page: 2

Unit 8 Assignment 1 HW
PT1420 Tuesday

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
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.
3. // 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. //Declare Integer number
Declare an accumulator variable
Declare Integer total = 0
Declare Integer counter
For counter = 1 to 10
Display “Enter a number.”
Input number
Set total = total + number
End For
Display “The total is”, total
9. Declare Integer count
For count < 50
Display “The count is “, count
Set count = 1 To 50
End For
10. //Declare integer count
While count

Similar Essays