English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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

2007-05-04 01:39:32 · 3 answers · asked by Zo Show 2 in Computers & Internet Programming & Design

3 answers

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?

2007-05-04 03:10:16 · answer #1 · answered by BlueFeather 6 · 0 0

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.

2007-05-04 08:13:13 · answer #2 · answered by fjpoblam 7 · 0 0

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

2007-05-04 01:53:58 · answer #3 · answered by kedarnath c 2 · 0 0

fedest.com, questions and answers