Preview

Code for an Infinite Loop

Satisfactory Essays
Open Document
Open Document
457 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Code for an Infinite Loop
Pt1420 Unit 8 Assignment 1: Homework
Short Answer Review Questions:

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.

Algorithm Workbench:

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 while

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 While
Display “The total is”, total

9. Declare Integer count
For count < 50
Display “The count is “, count
Set count = 1 To 50
End While

Programming Exercises

Average Rainfall

Declare integer years, months, inches
For years= 1 to 10 For months= 1 to 12 For inches= per month
Declare integer total= 0
Declare integer counter
Display “This program calculates the”
Display “average

You May Also Find These Documents Helpful

  • Satisfactory Essays

    Hsm/260 Week 2

    • 262 Words
    • 2 Pages

    accounting and that is that in the accrual method, the amount that is entered into the books is one that…

    • 262 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    PT1420 Unit 8 Lab 8

    • 365 Words
    • 2 Pages

    Calculating a Running Total, page 201): Asks for input of a number 5 times then adds all numbers into one total sum, example 2,4,6,8,10 = 30…

    • 365 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    a. Adds 2 to a and stores the result in b// Ans.)B = 2 + A…

    • 453 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    unit 7 assignment 1

    • 431 Words
    • 2 Pages

    4. What is a count-controlled loop? A count-controlled loop repeats a specific number of times.…

    • 431 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Pt1420 Assignment

    • 1058 Words
    • 5 Pages

    1) Initialization: the variable is initialized 2) Test: the loop tests the variable by comparing it to the maximum value 3) Increment: to increase the value during each iteration the loop increments the counter variable by adding 1 to it.…

    • 1058 Words
    • 5 Pages
    Satisfactory Essays
  • Good Essays

    unit 8 homework

    • 793 Words
    • 5 Pages

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

    • 793 Words
    • 5 Pages
    Good Essays
  • Good Essays

    Acc 340 Wk 1 Individual

    • 823 Words
    • 4 Pages

    Accounting technology is not new, and has been a part of calculating and tracking numbers throughout time. From Leonardo da Vinci who designed a device he labeled the “Codex Madrid” number machine to Blaise Pascal who invented the first early calculator to William Burroughs who created the first adding machine, those who specialized in numbers have sought ways of making the tasks of their profession or hobby much simpler. As time passed, more creations emerged to help accountants perform their expertise more accurately and faster. The first computer was built midway through the twentieth century. For the nearly 50 years that followed, huge computers designed to perform the simple task of calculating mathematical equations were eventually scaled down to fit on top of desks in consumers’ homes and offices. The world of accounting went from manually inputting data into a ledger to using electronic spreadsheets that eliminated the need for ledgers, calculators, pencils, and adding machines. Out with the hardcopy and in with the software.…

    • 823 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    Intro the Programming

    • 386 Words
    • 5 Pages

    When you call a(n) ______, it simply executes the statement it contains and then terminates.…

    • 386 Words
    • 5 Pages
    Satisfactory Essays
  • Good Essays

    Psychology Key Terms

    • 540 Words
    • 3 Pages

    algorithms - An algorithm is a set of instructions for solving a problem or completing a process…

    • 540 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    Nt1110 Unit 3 Assignment

    • 479 Words
    • 2 Pages

    An electronic calculator is a small, portable, often inexpensive electronic device used to perform both basic and complex operations of arithmetic.…

    • 479 Words
    • 2 Pages
    Powerful Essays
  • Good Essays

    Show all the possible interleavings of the execution of preceding two processes (Show this by giving execution “traces” in terms of the atomic statements)…

    • 810 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    CMIS102 Homework1

    • 703 Words
    • 3 Pages

    The task at hand is to design a program, using pseudocode, which will calculate the square feet of a house with no more than four rooms. It must be additionally assumed that each of these rooms is rectangular. The required output is the accurate calculation of the aggregate square footage of these rooms. The required input to arrive at this output is the length and width of each of the rooms, the multiplication of each individual room length and width, and the sum of the combined multiplication results. The required output will be obtained through proper declaration of each variable, which consists of multiple floating point values. For my analysis the length of a room will be represented as L plus a number to identify the room, such as L1. The width will similarly be represented as W1, and the area, or length times width, as A1. The resulting output, or sum of all A values, will be calculated. The following is a list of the required input and resulting output.…

    • 703 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Quality of Earning

    • 319 Words
    • 2 Pages

    Accrual Accounting: Accrual accounting introduces the idea of periodicity. Periodicity states that each transaction should be assigned to a given period and split accordingly if it covers several periods. This is an attempt to recognize revenues in the period in which they were actually earned (revenue recognition principle) as well as to match…

    • 319 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    could fail in the long term if a open-loop logic is adopted. On the contrary, by making explicit…

    • 5780 Words
    • 38 Pages
    Better Essays
  • Powerful Essays

    mas preboard

    • 7230 Words
    • 30 Pages

    b. The technique of executing a set of computer programs such that each completed before the next program of the set is started.…

    • 7230 Words
    • 30 Pages
    Powerful Essays