Unit 5 Flashcards
5.2 - Loops (General)
What is a loop?
a programming construct that allows us to repeat lines of code indefinitely
5.2 - Loops (General)
What is a loop body?
statements/lines of code executed within the loop
5.2 - Loops (General)
When are looping conditions evaluated?
When does the loop decide to repeat itself (based on a condition)?
after every full execution of the loop
5.3 - While Loops
What is a while loop?
the loop body executes while a condition is true
5.3 - While Loops
What is a sentinel-controlled loop ?
a while loop whose condition depends on a specific string/character value*
also called a sentinel value , which changes as the loop progresses
5.3 - While Loops
What is an infinite loop?
a loop with no termination condition
5.4 - More While Loop Examples
What is a docstring?
a multi-line comment that describes what the program does prior to execution
5.4 - More While Loop Examples
What is a flag-controlled loop?
a loop whose execution is determined by a Boolean value
5.4 - More While Loop Examples
What is an EOF-controlled loop?
a loop determined by “end of file” files
5.5 - Counting
How do you make a loop repeat a select number of times?
use i
as loop variable, repeat 3 times, assume i = 0
while i < 3
i = i + 1
or i += 1
5.7 - For Loops
What is a for loop?
a loop where a variable is assigned a value each iteration
used for lists, dictionaries, and tuples
5.7 - For Loops
What does reversed()
do?
reverses the order which elements are read through
ex. list = [1, 2, 3]
reversed(list) = [3, 2, 1]
5.8 - Counting Using the Range Function
What does range()
do?
generates a sequence of integers between a starting (inclusive) and ending integer (exclusive)
some ranges feature a third option (integer step value) that changes the rate which numbers are counted
ex. range(0, 11, 2)
counts every 2 numbers 0-10
Software Development Cycle
What is the Software Development Cycle?
- identify/state the problem
- analyze the problem
- design an algorithm to solve the problem
- impliment the algorithm via a computer program
- test/verify the program
- maintain and update the program