Iteration: Difference between revisions
Mr. MacKenty (talk | contribs) No edit summary |
Mr. MacKenty (talk | contribs) |
||
(10 intermediate revisions by the same user not shown) | |||
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. 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. | 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: | There are different types of iterations: | ||
Line 9: | Line 9: | ||
# iterate through elements in a list or array | # iterate through elements in a list or array | ||
When we iterate | 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 one == | |||
This is one of the better videos I've seen on iteration | |||
== | |||
This is one of the better videos I've seen on | |||
Line 26: | Line 21: | ||
</html> | </html> | ||
== | == Video two == | ||
<html> | <html> | ||
<iframe width="560" height="315" src="https://www.youtube.com/embed/l26oaHV7D40" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> | <iframe width="560" height="315" src="https://www.youtube.com/embed/l26oaHV7D40" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> | ||
</html> | </html> | ||
== Example one == | |||
<syntaxhighlight lang="python"> | |||
# This example is in the Python programming language | |||
for i in range (0,100): | |||
print(i) | |||
# output will be: | |||
0 | |||
1 | |||
2 | |||
3 | |||
4 | |||
5 | |||
... | |||
99 | |||
</syntaxhighlight> | |||
== Example two == | |||
<syntaxhighlight lang="python"> | |||
# This example is in the Python programming language | |||
myList = [1,3,5,11,22,33,44,55,66] | |||
for i in myList: | |||
print(i) | |||
# output will be: | |||
1 | |||
3 | |||
5 | |||
11 | |||
22 | |||
33 | |||
44 | |||
55 | |||
66 | |||
</syntaxhighlight> | |||
== Standards == | == Standards == | ||
Line 40: | Line 78: | ||
[[Category: | [[Category:programming]] |
Latest revision as of 16:10, 17 February 2020
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:
- iterate until a certain condition is reached
- iterate a certain number of times
- 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 one[edit]
This is one of the better videos I've seen on iteration
Video two[edit]
Example one[edit]
# This example is in the Python programming language
for i in range (0,100):
print(i)
# output will be:
0
1
2
3
4
5
...
99
Example two[edit]
# This example is in the Python programming language
myList = [1,3,5,11,22,33,44,55,66]
for i in myList:
print(i)
# output will be:
1
3
5
11
22
33
44
55
66
Standards[edit]
- Construct algorithms using loops, branching.