Repetition Structures Flashcards

1
Q

What does a repetition structure do?

A

It executes a statement or set of statements repeatedly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two types of loops in repetition structures?

A

Condition-Controlled Loop and Count-Controlled Loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a condition-controlled loop?

A

A loop that repeats based on a true/false condition.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a count-controlled loop?

A

A loop that repeats a specified number of times.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the key differences between a While loop, Do-While loop, and Do-Until loop?

A
  • While/Do-While: Repeats as long as a condition is true.
  • Do-Until: Repeats until a condition is true.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the two parts of a while loop?

A
  1. Condition: tested for true/false.
  2. Statement(s): executed while the condition is true.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is an infinite loop?

A

A loop that occurs if the condition never becomes false, running until interrupted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between a pretest and posttest loop?

A
  • 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).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the structure of a For loop?

A
  • Initialization: Starting value for the counter.
  • Test: Compares the counter to a maximum value.
  • Increment: Increases the counter each iteration.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does a counter variable in a For loop do?

A

It initializes, tests, and increments after each iteration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What symbol is used in flowcharts to represent loops?

A

A hexagon symbol.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can a count-controlled loop be implemented using a while loop?

A

A count-controlled loop can be designed using a while loop to control the number of iterations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is an accumulator in the context of a loop?

A

An accumulator is a variable that stores the running total as numbers are added in each iteration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a sentinel value?

A

A sentinel is a special value used to mark the end of a list of values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are nested loops?

A

A loop inside another loop, where the inner loop completes all iterations for each iteration of the outer loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you calculate the total iterations of nested loops?

A

The total iterations are the product of all loop iterations.