Iteration (Ch2) (M2) Flashcards
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