Free Online Flashcard Deck

4 Loops and Repetition Free Online FlashCards

Study 4 Loops and Repetition with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is iteration?

Back

Iteration is the repeated execution of a block of statements. A loop is the control structure that performs iteration.

02
Front

What three parts make a loop reliable?

Back

Initialization establishes the starting state, the condition determines whether another iteration occurs, and progress or update changes state toward termination.

03
Front

When should you use a for loop?

Back

Use a for loop when the number of repetitions or the range of values is known or easy to describe.

04
Front

What is the execution rule for while?

Back

A while loop tests its condition before the body runs, so the body may execute zero times.

05
Front

Why use a do...while loop?

Back

A do...while loop tests its condition after the body, so the body always executes at least once.

06
Front

What does a counter pattern do?

Back

A counter records how many times an event occurs. It changes only when the desired event occurs, unlike the loop-control variable, which may change every iteration.

07
Front

What is an accumulator?

Back

An accumulator combines many values into one result. A sum usually starts at 0, while a product usually starts at 1.

08
Front

How does the search pattern work?

Back

A search loop examines values until it finds a match or reaches the end. A sentinel such as -1 can represent “not found,” and break can stop the search after a match.

09
Front

What does a filtering loop do?

Back

A filtering loop processes or collects only values that satisfy a condition. For example, it can add temperatures less than or equal to 100 to a safe-temperature list.

10
Front

How do break and continue differ?

Back

break terminates the nearest enclosing loop. continue skips the rest of the current iteration and moves to the next one.

11
Front

When is for...of preferable for arrays?

Back

A for...of loop directly supplies each element of an iterable, such as an array. Use an indexed for loop when the element’s index is needed.

12
Front

How does a nested loop execute?

Back

For each outer-loop iteration, the inner loop completes all of its iterations. In the example, 3 rows multiplied by 4 columns gives 12 executions of the inner body.