Chapter 2 - Iteration Flashcards
What is iteration?
A procedure or set of commands that are repeated either a set number of times or while a condition is met.
What is definite iteration?
This is when the number of loops is known before the loop is started, e.g. a for loop
What is Indefinite iteration?
This is when a number of loops is not known before the loop is started
Give an example of definite iteration
for i in range(s):
print(‘Hello!’)
Give an example of indefinite iteration
a = 3
while a < 10:
print(‘a is currently: ‘ + a)
a += 1
Is a for loop definite or indefinite iteration
definite
is a while loop definite or indefinite iteration
indefinite
is a do…. until loop definite or indefinite iteration
indefinite
The condition-check in an indefinite iteration loop can contain several layers of what?
boolean logic
how may a programmer create a script?
- come up with an idea or be given a brief by a company
- sketch out a plan of the script using a list algorithm or flow diagram
- Convert plan to pseudo code
- write the script
- perform a dry run using a trace table
- test and analyse results
- improve code and repeat step 6
what is a syntax error
an error in the code cause by a spelling mistake, grammatical mistake or indentation error etc.
what is a logical error
the code does work but not as intended
what is a dry run
the script is run on paper and each stage is carefully analysed to see what values the various variables and outputs have
what is a trace table
the table that keeps track of the variables and outputs during a dry run