Iteration: Difference between revisions

From Computer Science Wiki
No edit summary
No edit summary
Line 9: Line 9:
# iterate through elements in a list or array
# iterate through elements in a list or array


When we iterate we track which iteration we are on. For example: if I am iterating 100 times (from zero to one hundred, incrementing by one each at each step), our programming language will keep track of '''which iteration''' we are cycling through.
When we iterate our programming language tracks what step of the iteration is currently being executed. For example: if we are iterating 100 times (from zero to one hundred, incrementing by one each at each step), our programming language will keep track of '''which iteration''' we are cycling through.  


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.  
Iteration is a fundamental programming idea that is commonly used in writing programs.


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.
== Video: ==  
 
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>.
 
 
== Introduction ==  
This is one of the better videos I've seen on loops. Content gratefully used with permission :  <ref>http://cs50.tv/2015/fall/#license,psets</ref>. The video uses programming syntax from the C programming language, but the main ideas are helpful in understanding loops.
This is one of the better videos I've seen on loops. Content gratefully used with permission :  <ref>http://cs50.tv/2015/fall/#license,psets</ref>. The video uses programming syntax from the C programming language, but the main ideas are helpful in understanding loops.



Revision as of 13:11, 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". As a computer scientist, we use specialized vocabulary to communicate with other computer scientists. -

There are different types of iterations:

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

When we iterate our programming language tracks what step of the iteration is currently being executed. For example: if we are iterating 100 times (from zero to one hundred, incrementing by one each at each step), our programming language will keep track of which iteration we are cycling through.

Iteration is a fundamental programming idea that is commonly used in writing programs.

Video:[edit]

This is one of the better videos I've seen on loops. Content gratefully used with permission : [1]. 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]