Free Online Flashcard Deck

4 Repetition and Looping Free Online FlashCards

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

12 cards
01
Front

When can a while loop execute zero times?

Back

A while loop tests its condition before each iteration, so its body can execute zero times.

02
Front

What guarantees that a do-while loop runs once?

Back

A do-while loop executes its body before testing the condition, so it always runs at least once.

03
Front

What punctuation follows a do-while condition?

Back

The semicolon terminates the do-while statement: do { /* body */ } while (condition);

04
Front

What is the execution order of a for loop?

Back

A for loop initializes once, tests before each iteration, runs the body, updates, and then tests again.

05
Front

When is a for loop a natural choice?

Back

Use a for loop when a counter or another regular progression naturally describes the repetition.

06
Front

What does break do inside a loop?

Back

break immediately exits the nearest enclosing loop and continues with the first statement after that loop.

07
Front

What does continue do in a for loop?

Back

continue skips the rest of the current iteration and begins the next one. In a for loop, the update runs first.

08
Front

How many times can a nested-loop body execute?

Back

A nested loop's body executes once for each outer iteration combined with each inner iteration: r times c times, or r×cr \times c.

09
Front

What is the structure of an accumulation loop?

Back

Initialize an accumulator before the loop, then update it once per visited value, such as total += value.

10
Front

How does a loop count matching values?

Back

A counting loop increments a counter whenever an item satisfies a condition, such as value > 0.

11
Front

What is a sentinel-controlled loop?

Back

A sentinel-controlled loop stops when a special value appears; in the example, -1 ends input and is not added to the total.

12
Front

Which index condition avoids an array off-by-one error?

Back

For a zero-based array with size elements, use i < size because valid indices are 0 through size - 1.