Repetition Structures Flashcards
What does a repetition structure do?
It executes a statement or set of statements repeatedly.
What are the two types of loops in repetition structures?
Condition-Controlled Loop and Count-Controlled Loop.
What is a condition-controlled loop?
A loop that repeats based on a true/false condition.
What is a count-controlled loop?
A loop that repeats a specified number of times.
What are the key differences between a While loop, Do-While loop, and Do-Until loop?
- While/Do-While: Repeats as long as a condition is true.
- Do-Until: Repeats until a condition is true.
What are the two parts of a while loop?
- Condition: tested for true/false.
- Statement(s): executed while the condition is true.
What is an infinite loop?
A loop that occurs if the condition never becomes false, running until interrupted.
What is the difference between a pretest and posttest loop?
- Pretest loop: Condition is tested before executing the body (e.g., While).
- Posttest loop: Executes the body at least once before testing the condition (e.g., Do-While).
What is the structure of a For loop?
- Initialization: Starting value for the counter.
- Test: Compares the counter to a maximum value.
- Increment: Increases the counter each iteration.
What does a counter variable in a For loop do?
It initializes, tests, and increments after each iteration.
What symbol is used in flowcharts to represent loops?
A hexagon symbol.
How can a count-controlled loop be implemented using a while loop?
A count-controlled loop can be designed using a while loop to control the number of iterations.
What is an accumulator in the context of a loop?
An accumulator is a variable that stores the running total as numbers are added in each iteration.
What is a sentinel value?
A sentinel is a special value used to mark the end of a list of values.
What are nested loops?
A loop inside another loop, where the inner loop completes all iterations for each iteration of the outer loop.
How do you calculate the total iterations of nested loops?
The total iterations are the product of all loop iterations.