1/19
Flashcards covering parallel arrays, range matching, array bounds, for loops, pretest/posttest loop types, structured looping, and switch-case decision structures based on lecture notes.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What are parallel arrays and how are their elements linked?
Parallel arrays are two or more arrays containing related data of potentially different data types, where the same relative position (subscript or index) links corresponding elements together.

Which visual structure links item numbers to prices at matching relative positions in parallel arrays?
In parallel arrays, corresponding data items share the same subscript position across separate arrays, such as index 4 linking item 457 in VALID_ITEMS to price 17.5 in VALID_PRICES.
What is the highest usable index in an array containing N elements?
The highest usable index is N−1, because array indexing is 0-based (ranging from index 0 through index N−1).
What is an off-by-one error in array indexing?
It is a common logic mistake occurring when array indexing is assumed to start at 1 instead of 0, resulting in skipping the first element (at index 0) and attempting to access an invalid out-of-bounds position (at index N).
What role does a flag variable play in an exact-match search?
A flag variable (such as foundIt, initialized to "N") records whether a matching element has been located during array traversal.
How does range matching differ from exact-match searching?
An exact match determines whether a value equals a specific array element, whereas a range match determines which numerical category or bracket (bounded by range limits) an input value belongs to.
What are the three essential steps required to manage a loop control variable (LCV)?
The three steps are: 1) Initialize the loop control variable before loop entry, 2) Test the variable in the loop condition, and 3) Alter the variable inside the loop body toward the stopping condition.
What is the key difference between a pretest loop and a posttest loop?
A pretest loop (such as while or for) tests the condition before executing the loop body and may execute zero times, whereas a posttest loop (such as do-while) checks the condition after executing the body, guaranteeing at least one execution.
What defines a structured loop?
A structured loop is governed by exactly one loop-controlling evaluation that provides the single entry into or exit from the loop structure.
How is the total number of iterations calculated for nested loops?
The total number of iterations is calculated as the outer loop count multiplied by the inner loop count (Total Iterations=Outer Count×Inner Count).
What is the primary difference between a counter variable and an accumulator variable?
A counter variable usually increments by a fixed step value (such as 1) to count repetitions or events, whereas an accumulator gathers a variable sum (such as adding transaction prices to a running total).
What primary root cause produces an infinite loop during program execution?
An infinite loop occurs when the loop condition never evaluates to FALSE, most frequently caused by forgetting to alter or update the loop control variable inside the loop body.
In for loop syntax, what do the initial value, final value, and step value define?
The initial value sets where the loop control variable begins, the final value sets the limit used to terminate the loop, and the step value specifies how much the variable changes (increments or decrements) per iteration.
When is a switch-case structure preferred over an if-else-if ladder?
A switch-case structure is preferred when evaluating a single variable against multiple exact, discrete match values (such as menu choices), producing cleaner and more organized code.
What is the purpose of the default (or OTHERWISE) block in a switch-case structure?
It serves as a catch-all safety net that executes when none of the explicitly specified exact match cases correspond to the evaluated expression.
Why is using an array subscript like counts[dep] = counts[dep] + 1 superior to nested decisions for counting categories?
Using dep as the array subscript allows a single statement to update any category count, eliminating repetitive if-else blocks and making code easier to maintain if categories expand.
What is a sentinel value in an indefinite loop?
A sentinel value is a designated special input (such as "STOP") that signals the loop to terminate when the exact number of repetitions is not known in advance.
Why should invariant statements be placed outside a loop rather than inside?
Placing statements that do not change during iteration (such as discountRate = 0.30) inside a loop causes redundant, unnecessary recalculations on every iteration.
What is the principle of GIGO in relation to loop-based data validation?
GIGO stands for Garbage In, Garbage Out, emphasizing that while validation loops ensure input meets required formats or ranges, they cannot verify if the data is factually true, so bad input still produces worthless output.
How does a for loop process array elements sequentially and safely?
A for loop uses a subscript variable starting at 0 and stepping by 1 up to ARRAY_LIMIT - 1 (or SIZE - 1), systematically accessing every element without exceeding valid array bounds.