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
Infinite loop
(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!
==Examples of intentional infinite loops== A simple example (in [[C (programming language)|C]]): <syntaxhighlight lang="c"> #include <stdio.h> int main() { for (;;) // or equivalently, while (1) printf("Infinite Loop\n"); return 0; } </syntaxhighlight> The form <code>for (;;)</code> for an infinite loop is traditional, appearing in the standard reference ''[[The C Programming Language]]'', and is often punningly pronounced "forever".<ref>{{Cite web |url=https://stackoverflow.com/questions/20186809/endless-loop-in-c-c |title=Endless loop in C/C++ |url-status=live |archive-url=https://web.archive.org/web/20160803202212/http://stackoverflow.com/questions/20186809/endless-loop-in-c-c |archive-date=2016-08-03}}</ref> This is a loop that will print "Infinite Loop" without halting. A similar example in 1980s-era [[BASIC programming language|BASIC]]: <syntaxhighlight lang="basic"> 10 PRINT "INFINITE LOOP" 20 GOTO 10 </syntaxhighlight> A similar example in [[MS-DOS]] compatible batch files: <syntaxhighlight lang="bat"> :A echo Infinite Loop goto :A </syntaxhighlight> In [[Java (programming language)|Java]]: <syntaxhighlight lang="java"> while (true) { System.out.println("Infinite Loop"); } </syntaxhighlight> The while loop never terminates because its condition is always true. In [[Bourne Again Shell]]: <syntaxhighlight lang="bash"> for ((;;)); do echo "Infinite Loop" done </syntaxhighlight> In [[Rust (programming language)|Rust]]: <syntaxhighlight lang="rust"> loop { println!("Infinite loop"); } </syntaxhighlight>
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)