Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Explain with an example the need for iteration in a computer program.?

It is for an intro computer class if any knows just holla at me

3 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Here is a simple example (VBA style) that might help clarify the concept:

    Say you have an array (call it A) of 100 numbers that you want to add together and come up with a total.

    WITHOUT ITERATION:

    Initialize a variable to zero, then add each array element to it.

    Total = 0

    Total = Total + A(1)

    Total = Total + A(2)

    Total = Total + A(3)

    and so on, down to

    Total = Total + A(100)

    In this case you have write 100 separate statements!

    WITH ITERATION:

    Total = 0

    For n = 1 To 100

    Total = Total + A(n)

    Next n

    See the difference now?

  • 1 decade ago

    Iteration is used to tell the computer the name of a set of things, the number of things in that set, and the thing to do to each thing in that set (like, say, capitalize the first letter of a set of names).

    If you have twenty names, you could write twenty instructions, each of which capitalizes the first letter of one name. Or, with iteration, you can give the computer a way to do the same thing over and over twenty times. Iteration saves space in the computer's memory, because the ability to store the instruction for capitalization instruction just once is shorter than having to store it twenty times.

    Further, it allows easier use of future lists to be input by simply adding a new list rather than typing a whole new "capitalize" instruction.

  • 1 decade ago

    Basically Iterators are used to go thru the collection of objects.

Still have questions? Get your answers by asking now.