Chapter 5 (Loops) Flashcards
One set of instructions that operate on multiple, separate sets of data
Loop
This keyword starts the loop body and precedes any statements that execute when the tested condition is True.
While
What keyword ends the “while” loop structure?
Endwhile
What does the loop control variable do?
Manages the number of repetitions a loop performs.
What are the 3 actions that should occur when using a loop control variable:
- INITIALIZE the variable before entering the loop.
- TEST the variable to see if the result is True, before entering the loop.
- Set conditions which allow the variable to be ALTERed within the body of the loop.
What is the significance of making the loop control variable alterable within the body of the loop?
It allows the tested condition to return as false, which will make the loop end (eventually).
Initializing the loop control variable is essentially providing the loop with a ______ ____.
starting value
The 3 separate actions concerning a loop control variable prevents ______ _____.
infinite loops
What are 2 common loop control variable types?
- a counter
2. a sentinel value
Sentinel values as a loop control variable are used to create what type of loop?
indefinite
These loops execute a predetermined number of times.
Definite loops
A counter is any numeric value that counts the number of times an event has occurred. What is the best number to start a counted loop at?
0
This naturally lends itself to definite loops with a starting value/counter of 0
array manipulation
Is starting a counter loop at 0 necessary?
No, but it is encouraged.
Counted loops are a program that track the number of loop repetitions by counting them. What is another name for counted loops?
Counter-controlled loops.
These loops perform a varying amount of times.
Indefinite loops
<> is a ______ symbol
placeholder
What is the name of this placeholder symbol: <>
Not-equal-to-operator
Evaluates as True when its operands are not equivalent/identical
<>
What are loops within loops?
Nested loops
The nested loop contains:
At least 1 outer loop, and at least 1 inner loop
An inner loop goes through all of its iterations each time that an outer loop goes through how many iterations?
One
# of inner loop iterations * # of outer loop iterations The above is...
the formula for the total number of iterations executed by a nested loop.
Another phrase for the “for statement”
For loop
For statements are used for what type of loop?
Definite loops
What is the keyword that ends for statements?
endfor
Step value is…
the amount by which a for loop control variable changes.
The step value can be any number. If the step value is positive or negative this implies ______ or ______ a value.
incrementing, decrementing
The for loop provides a convenient shorthand for what type of loop?
a While loop
What allows a for loop to be a shorthand version of a while loop?
They are both used for definite loops where the loop control variable progresses from a known starting value to a known ending value IN EQUAL STEPS.
Which loop is particularly useful for processing arrays?
For loop
What does the expression count++ do in a for loop?
It increases count by 1.
The loop control variable is tested before each iteration in a…
Pretest loop
What is the significance of a pretest loop?
It allows it so that a loop body might never execute, because the evaluation controlling the loop might be false the first time it is made.
The loop body executes at least once in this type of loop
Posttest loop
In a posttest loop, the loop control variable is not tested until after the 1st ______
iteration.
What is another name for the posttest loop?
do while loop
In a do while loop, the action you “do” _______ testing the condition.
precedes
a ______ followed by a pretest while loop is the equivalent of a do while loop.
sequence
What is the significance of these two characteristics?
- The loop-controlling evaluation must provide either the entry to or exit from the structure.
- The loop-controlling evaluation provides the ONLY entry to or exit from the structure
These are the characteristics all structured loops (both pretest and posttest) have in common.
A variable used to gather values, similar to a counter that you use to count loop iterations
Accumulator
What are the 3 actions that must be taken with an accumulator?
- INITIALIZE it to 0
- ALTER the accumulator for every dataset processed
- OUTPUT the accumulator’s value at the end of all processing.
The accumulator variable is most often altered by using _______.
Addition
Variables only exist during an _________ of the program.
execution
These contain only totals, and have no data for individual records.
Summary reports
Programming that tries to prepare for all possible errors before they occur.
Defensive programming
What is the function that a loop performs when used to make sure that data is meaningful, useful, is the correct data type, or falls within an acceptable range?
Validate data
GIGO stands for
“Garbage in, garbage out”
What does GIGO mean?
If your input is incorrect, your output is worthless.
Forcing a data item means you ________ incorrect data by setting the variable to a specific, predetermined value.
override
Using the module’s results without understanding its internal statements means employing a…
Black box variable
What are 3 methods used to ensure data is valid?
- DISPLAY error message
- CHOOSE A DEFAULT VALUE before proceeding to the next step with a garbage input.
- REPROMPT the user for valid input.
In the ________ ________, the two logical paths that emerge from testing the condition join together following their actions.
selection structure
In a ____ _______, the paths that emerge from a tested condition do not joint together.
Loop structure
One of the logical branches that emerges from the _______-_________ _______ eventually returns to the same test, in a loop structure.
structure-controlling decision
Selections and loops both begin with a _______ expression and both structures have a body that executes when said expression is evaluated as _____.
Boolean; True
When nesting loops, you maintain two ________ loop control variables and alter each at the appropriate time.
separate
The ___ statement uses a loop control variable that it automatically initializes, tests, and alters.
For
The loop body executes at least one time in a…
posttest loop
____ count = 0 to 3 step 1
______ “Hello”
______
for; output; endfor
count = 0 \_\_\_\_\_ count <= 3 output "Hello" count = \_\_\_\_\_\_ + \_\_ \_\_\_\_\_\_\_\_
while; count; 1; endwhile
the amount by which a loop control variable changes is called a ____ value.
step
for loops and while loops are types of _____ loops.
pretest