Iteration: Difference between revisions

From Computer Science Wiki
No edit summary
Line 1: Line 1:
[[File:computation.png|frame|right|This is a basic concept in computer science]]
[[File:computation.png|frame|right|This is a basic concept in computer science]]


In computer programming, iteration is a sequence of instructions that is continually repeated until a certain condition is reached or a condition is declared FALSE. Typically, a certain process is done, such as getting an item of data and changing it, and then some condition is checked such as whether a counter has reached a prescribed number. If it hasn't, the next instruction in the sequence is an instruction to return to the first instruction in the sequence and repeat the sequence. If the condition has been reached, the next instruction "falls through" to the next sequential instruction or branches outside the loop. A loop is a fundamental programming idea that is commonly used in writing programs.
In computer programming, iteration is a sequence of instructions that is continually repeated. You can think of iteration as a loop, but please use the word "iteration" or "iterate" in this class.  


An infinite loop is one that lacks a functioning exit routine . The result is that the loop repeats continually until the operating system senses it and terminates the program with an error or until some other event occurs (such as having the program automatically terminate after a certain duration of time) <ref>http://whatis.techtarget.com/definition/loop</ref>.
There are different kinds of iterations:
 
# iterate until a certain condition is reached
# iterate a certain number of times
# iterate until a condition is declared FALSE
# iterate through elements in a list or array
 
When we iterate we  stop and "do something" in each iteration. For example, we might get an item of data and change it. Or, we might check if some condition such as whether a counter has reached a prescribed number.
 
If it hasn't, the next instruction in the sequence is an instruction to return to the first instruction in the sequence and repeat the sequence. If the condition has been reached, the next instruction "falls through" to the next sequential instruction or branches outside the loop. A loop is a fundamental programming idea that is commonly used in writing programs.
 
An infinite loop is one that lacks a functioning exit routine. The result is that the loop repeats continually until the operating system senses it and terminates the program with an error or until some other event occurs (such as having the program automatically terminate after a certain duration of time) <ref>http://whatis.techtarget.com/definition/loop</ref>.





Revision as of 12:21, 18 June 2019

This is a basic concept in computer science

In computer programming, iteration is a sequence of instructions that is continually repeated. You can think of iteration as a loop, but please use the word "iteration" or "iterate" in this class.

There are different kinds of iterations:

  1. iterate until a certain condition is reached
  2. iterate a certain number of times
  3. iterate until a condition is declared FALSE
  4. iterate through elements in a list or array

When we iterate we stop and "do something" in each iteration. For example, we might get an item of data and change it. Or, we might check if some condition such as whether a counter has reached a prescribed number.

If it hasn't, the next instruction in the sequence is an instruction to return to the first instruction in the sequence and repeat the sequence. If the condition has been reached, the next instruction "falls through" to the next sequential instruction or branches outside the loop. A loop is a fundamental programming idea that is commonly used in writing programs.

An infinite loop is one that lacks a functioning exit routine. The result is that the loop repeats continually until the operating system senses it and terminates the program with an error or until some other event occurs (such as having the program automatically terminate after a certain duration of time) [1].


Introduction[edit]

This is one of the better videos I've seen on loops. Content gratefully used with permission : [2]. The video uses programming syntax from the C programming language, but the main ideas are helpful in understanding loops.


A good video[edit]

Standards[edit]

  • Construct algorithms using loops, branching.

References[edit]