Karteikarten
Iteration revision
Karten in diesem Stapel (8)
- 1Iteration - Lesson 3- Understand and use iteration in an algorithm
- Write algorithms in pseudocode involving sequence, selection and iteration
- Trace through given algorithms to explain what they do, correct or complete them - 2What is iteration??Iteration is when parts of an algorithm need repeating
- 3What are the two types of iteration statements in python??- FOR... TO ... NEXT
-WHILE ... DO ... UNTIL - 4Why are FOR loops useful and the most efficient type of loop??A FOR loop can be set for a specific amount of times, so is set up with a start value and a ending value. The loop only ends when the end value is reached. This type of loop is useful for reading values into lists.
- 5Example of a FOR loop:Total <- 0(put 0 into it)
FOR Counter <- 1 TO 7
MaxTemperature <- USERINPUT
Add MaxTemperature to Total
NEXT Counter
AverageWeeksTemp <- Total/7
Output (“This week’s average is ”, AverageWeeksTemp) - 6When do you use a WHILE loop??when the number of repetitions/iterations is not known and the actions are only repeated WHILE a given condition is TRUE.
The condition must be tested at the beginning of the loop. - 7Example of a WHILE loop:emailAddress <- USERINPUT
While emailAddress does not contain “@”
Output “Invalid address – please re-enter”
emailAddress <- USERINPUT
Endwhile
Output “Thank you” - 8TIP: to help you understand how while loops work try laying it out as a flowchart where if the user doesn't do something it returns to the beginning.TIP TIP TIP