Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Loop invariant
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Invariants used to prove properties of loops}} {{for|the computer programming optimization technique|Loop-invariant code motion}} In [[computer science]], a '''loop invariant''' is a property of a [[Computer program|program]] [[Control flow#Loops|loop]] that is true before (and after) each iteration. It is a [[logical assertion]], sometimes checked with a code [[Assertion (software development)|assertion]]. Knowing its invariant(s) is essential in understanding the effect of a loop. In [[formal verification|formal program verification]], particularly the [[Hoare logic|Floyd-Hoare approach]], loop invariants are expressed by formal [[predicate logic]] and used to prove properties of loops and by extension [[algorithm]]s that employ loops (usually [[Correctness (computer science)|correctness]] properties). The loop invariants will be true on entry into a loop and following each iteration, so that on exit from the loop both the loop invariants and the loop termination condition can be guaranteed. From a programming methodology viewpoint, the loop invariant can be viewed as a more abstract specification of the loop, which characterizes the deeper purpose of the loop beyond the details of this implementation. A survey article <ref>Carlo A. Furia, [[Bertrand Meyer]] and Sergey Velder. "Loop invariants: analysis, classification, and examples."ACM Computing Surveys. vol. 46, no. 3, February 2014([http://se.ethz.ch/~meyer/publications/methodology/invariants.pdf]</ref> covers fundamental algorithms from many areas of computer science (searching, sorting, optimization, arithmetic etc.), characterizing each of them from the viewpoint of its invariant. Because of the similarity of loops and [[recursion|recursive]] programs, proving partial correctness of loops with invariants is very similar to proving the correctness of recursive programs via [[structural induction|induction]]. In fact, the loop invariant is often the same as the inductive hypothesis to be proved for a recursive program equivalent to a given loop.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)