Multiple choice

Which of these may be programmed as an assertion?

  1. foreach loop

  2. while loop

  3. loop variant

  4. recursion

  5. loop invariant

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

In computer science, a loop is a programming language statement that allows code to be repeatedly executed; an invariant of a loop is a property that holds before (and after) each repetition. It is a logical assertion, sometimes programmed as an assertion. Knowing its invariant(s) is essential for understanding the effect of a loop.