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!
==Use of loop invariants== A loop invariant can serve one of the following purposes: # purely documentary # to be checked within in the code, e.g. by an assertion call # to be verified based on the [[Hoare logic|Floyd–Hoare approach]] For 1., a natural language comment (like <code>// m equals the maximum value in a[0...i-1]</code> in the [[#Informal example|above]] example) is sufficient. For 2., programming language support is required, such as the [[C (programming language)|C]] library [[assert.h]], or the [[#Eiffel|above]]-shown <code>invariant</code> clause in Eiffel. Often, run-time checking can be switched on (for debugging runs) and off (for production runs) by a compiler or a runtime option.{{citation needed|reason=hope that C's or/and Eiffel assert.h supports that?|date=May 2016}} For 3., some tools exist to support mathematical proofs, usually based on the [[#Floyd–Hoare logic|above]]-shown Floyd–Hoare rule, that a given loop code in fact satisfies a given (set of) loop invariant(s). The technique of [[abstract interpretation]] can be used to detect loop invariant of given code automatically. However, this approach is limited to very simple invariants (such as <code>0<=i && i<=n && i%2==0</code>).
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)