Module 4 Flashcards
While loop
Executes instructions repeatedly while a condition is true.
while CONDITION :
STATEMENTS
count-controlled vs. event controlled
count controlled (aka definite) is used more-so as a counter and can be used a definite number of times, where as event controlled (indefinite) executes until an event occurs
typical outline of a while loop
Update the loop variable
# Check the loop variable ( while ____ <= n)
# Update the loop variable ( VARIABLE +1)
# Print results
When does a while loop not display an output?
When the loop is false, or when the loop runs forever
What is an off-by-one error?
A common error when programming loops. Think through simple test cases to avoid this type of error.
named argument
end= “”
by adding this as the last argument to the first print function, we indicate that an empty string is to be printed after the first argument is displayed. The output of the next print function starts on the same line where the previous one left off.
Example:
print(“00”, end=” “)
print(3+4)
output: 007
sentinel value
denotes the end of a data set, but it is not part of the data
priming read
the input operation before the loop, because it prepares or initializes the loop variable
modification read
the input operation at the bottom of the loop is used to obtain the next input. It modifies the loop variable inside the loop.