Iteration revision

Description

Iteration revision
Helena Frawley
Flashcards by Helena Frawley, updated more than 1 year ago
Helena Frawley
Created by Helena Frawley almost 8 years ago
18
1

Resource summary

Question Answer
Iteration - 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
What is iteration?? Iteration is when parts of an algorithm need repeating
What are the two types of iteration statements in python?? - FOR... TO ... NEXT -WHILE ... DO ... UNTIL
Why 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.
Example 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)
When 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.
Example of a WHILE loop: emailAddress <- USERINPUT While emailAddress does not contain “@” Output “Invalid address – please re-enter” emailAddress <- USERINPUT Endwhile Output “Thank you”
TIP: 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
Show full summary Hide full summary

Similar

Computing Hardware - CPU and Memory
ollietablet123
SFDC App Builder 2
Parker Webb-Mitchell
Data Types
Jacob Sedore
Intake7 BIM L1
Stanley Chia
Software Processes
Nurul Aiman Abdu
Design Patterns
Erica Solum
CCNA Answers – CCNA Exam
Abdul Demir
Abstraction
Shannon Anderson-Rush
Spyware
Sam2
HTTPS explained with Carrier Pigeons
Shannon Anderson-Rush
Data Analytics
anelvr