Iteration (Ch2) (M2) Flashcards
(34 cards)
What is iteration?
Iteration is the act of repeating a process until there is a desired result
When is iteration needed?
Iteration is needed when producing an algorithm because it means that you don’t have to write the same thing out lots of times - it makes code more efficient
What is definite iteration?
Definite iteration is where the number of iterations is known before the execution
What are the two examples of definite iteration?
Examples of definite iteration: FOR, IF
What do IF statements allow you to do?
IF statements allow you to check if a condition is true or false, and carry out different actions depending on the outcome.
What do nested IF statements allow you to do?
Nested IF statements allow you to check more conditions once you’ve established that the previous condition is true.
How are IF-ELSE-IF statements different from nested IF statements?
IF-ELSE-IF statements are different from nested IF statements as they only check more conditions if the previous condition is false.
What is a nested IF statement?
A nested IF statement is one IF statement inside of another one
What do FOR loops do?
FOR loops will repeat the code inside them a fixed number of times.
The number of times that a FOR loop repeats depends on what?
The number of times that the code repeats will depend on:
An intitial value, end value and the step count.
What is stepping used for in loops?
Stepping is used to move through a loop by different amounts
What is indefinite iteration?
Indefinite iteration is where the number of iterations isn’t known before the execution
Where are while loops controlled by a condition?
While loops are controlled by a condition at the start of the loop.
If the condition is false, what happens to the code inside of a while loop?
If the condition is false, the code inside a while loop is never run
If the condition is true, what happens to the code inside of a while loop?
If the condition is true, the code inside a while loop is always run
Where is the condition controlled in a DO UNTIL loop?
DO UNTIL loops are controlled by a condition at the end of the loop
What is the difference between a WHILE and DO UNTIL loop?
The difference between a WHILE and DO … UNTIL loop is:
A DO … UNTIL loop does the comparison at the end of the block, but a WHILE loop does it at the start of the block.
How many times at least, does a DO UNTIL loop run?
DO UNTIL loops always run the code inside them at least once
If the condition is never true, what happens to the DO UNTIL loop?
If the condition is never true, the loop is infinite
DO UNTIL loops continue until what?
DO UNTIL loops continue until the conditon is true
What is a nested loop?
A nested loop is when at least one loop exists inside another loop
What is a dry run?
A dry run is where the program is run on paper and is carefully analysed to fix any errors.
What is a trace table?
A trace table is a table which shows the values of each variable, input and output and how they change. This is made while a dry run is being worked through.
Trace tables make sure there are no type of what error?
Trace tables make sure there are no logic errors