A decreasing measure used to prove algorithm termination. A nonnegative integer loop variant must strictly decrease after every completed body whose condition was true; the body itself must terminate.[ref]
Loop invariants. CS 2112 Fall 2019; Loop invariants, Using loop invariants to show code is correct: Termination and the decrementing function
The prefix maximum correctness example uses V=n−k. It counts unread entries and is independent of whether the new entry changes the maximum. Ties therefore cannot stall progress: k increases even when best stays the same. An integer bounded below cannot strictly decrease indefinitely, which supplies the missing algorithm termination argument.
Control flow and four proof obligations for the prefix maximum correctness example
. Initialization, preservation, and exit establish partial correctness; the loop variant establishes algorithm termination and hence total correctness. The loop invariant is restored after both variable assignments. The input array stays unchanged throughout. Details. Ancestors (5)
Incoming links (130)
- Algorithm termination
- Coupled binary exponentiation
- Fixed-point pruning of finite constraint domains
- Formal methods
- Formal verification
- Greedy Egyptian fraction expansion
- Hoare logic
- Loop variant
- Past exam of the year 1 of the computer science course of the University of Oxford / 2003 / Functional programming, data structures and algorithms, procedural programming, and digital hardware / 4 / d / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2003 / Functional programming, data structures and algorithms, procedural programming, and digital hardware / 6 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2003 / Functional programming, data structures and algorithms, procedural programming, and digital hardware / 6 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2005 / Functional programming, data structures and algorithms, procedural programming, and digital hardware / 6 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2005 / Functional programming, data structures and algorithms, procedural programming, and digital hardware / 7 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2005 / Functional programming, data structures and algorithms, procedural programming, and digital hardware / 8 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2005 / Functional programming, data structures and algorithms, procedural programming, and digital hardware / 8 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2013 / Imperative programming / 1 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2013 / Imperative programming / 1 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2013 / Imperative programming / 2 / b / ii / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2013 / Imperative programming / 3 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2013 / Imperative programming / 3 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2013 / Imperative programming / 4 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2013 / Imperative programming / 4 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2013 / Imperative programming / 6 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2013 / Imperative programming / 8 / d / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2014 / Digital systems, linear algebra, introduction to formal proof / 1 / c / i / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2014 / Imperative programming / 1 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2014 / Imperative programming / 2 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2015 / Imperative programming / 2 / d / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2015 / Imperative programming (resit) / 1 / g / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2015 / Imperative programming (resit) / 2 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2015 / Imperative programming (resit) / 2 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2015 / Imperative programming (resit) / 3 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2015 / Imperative programming (resit) / 3 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2015 / Imperative programming (resit) / 3 / d / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2015 / Imperative programming (resit) / 3 / f / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2015 / Imperative programming (resit) / 4 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2015 / Imperative programming (resit) / 4 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2015 / Imperative programming (resit) / 4 / d / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2015 / Imperative programming (resit) / 7 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2015 / Imperative programming (resit) / 7 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2016 / Imperative programming / 1 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2016 / Imperative programming / 1 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2016 / Imperative programming / 1 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2016 / Imperative programming / 2 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2016 / Imperative programming / 3 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2016 / Imperative programming / 4 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2016 / Imperative programming / 4 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2016 / Imperative programming / 4 / c / iv / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2016 / Imperative programming (resit) / 4 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2016 / Imperative programming (resit) / 4 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2016 / Imperative programming (resit) / 4 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2017 / Discrete mathematics, continuous mathematics and probability / 2 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2017 / Imperative programming / 2 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2017 / Imperative programming / 3 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2017 / Imperative programming / 4 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2017 / Imperative programming / 4 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2017 / Imperative programming / 4 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2017 / Imperative programming / 4 / d / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2017 / Imperative programming (resit) / 2 / e / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2018 / Imperative programming / 1 / a / ii / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2018 / Imperative programming / 1 / a / i / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2018 / Imperative programming / 1 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2018 / Imperative programming / 1 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2018 / Imperative programming / 2 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2018 / Imperative programming / 2 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2018 / Imperative programming / 3 / d / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2018 / Imperative programming / 3 / e / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2018 / Imperative programming / 3 / f / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2018 / Imperative programming / 3 / g / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2018 / Imperative programming / 4 / d / i / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2018 / Imperative programming / 5 / d / iii / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2018 / Imperative programming / 5 / d / ii / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming / 1 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming / 1 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming / 1 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming / 1 / d / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming / 1 / e / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming / 2 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming / 2 / d / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming / 3 / a / ii / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming / 3 / d / i / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming / 4 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming / 4 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming / 4 / d / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming / 5 / d / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming / 6 / f / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming resit / 1 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming resit / 1 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming resit / 1 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming resit / 1 / d / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming resit / 1 / e / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming resit / 2 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming resit / 2 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming resit / 3 / e / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming resit / 3 / g / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming resit / 4 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming resit / 5 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming resit / 5 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2019 / Imperative programming resit / 7 / b / ii / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2021 / Imperative programming / 1 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2021 / Imperative programming / 1 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2021 / Imperative programming / 1 / d / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2021 / Imperative programming / 2 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2021 / Imperative programming / 4 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2021 / Imperative programming / 4 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2021 / Imperative programming / 4 / e / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2021 / Imperative programming / 5 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2021 / Imperative programming / 8 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2021 / Imperative programming (resit) / 1 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2021 / Imperative programming (resit) / 1 / e / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2021 / Imperative programming (resit) / 2 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2022 / Imperative programming (resit) / 1 / a / ii / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2022 / Imperative programming (resit) / 1 / a / i / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2022 / Imperative programming (resit) / 1 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2022 / Imperative programming (resit) / 1 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2022 / Imperative programming (resit) / 2 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2022 / Imperative programming (resit) / 2 / e / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2023 / Imperative programming / 1 / a / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2023 / Imperative programming / 1 / b / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2023 / Imperative programming / 1 / c / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2023 / Imperative programming / 2 / d / Solution
- Past exam of the year 1 of the computer science course of the University of Oxford / 2023 / Imperative programming / 4 / c / Solution
- Prefix maximum correctness example
- Sign-bracketing binary search
- Simultaneous exponentiation by squaring
- Summation loop verification
- Total correctness
- Two-way array partition
- Upper-bound search
- While loop
Discussion (0) New discussion
There are no discussions about this article yet.
Articles by others on the same topic (1)
A **loop variant** is a concept used in computer science, particularly in the context of program verification and formal methods. It is a condition that helps ensure that a loop terminates successfully and does not run indefinitely. A loop variant is typically a scalar value (it could be an integer or another comparable type) associated with a loop that satisfies two main properties: 1. **Initialization**: The loop variant must be initialized before the loop starts executing.
