programming idiom
infinite loop bsod
In computer programming, an infinite loop (or endless loop) is a sequence of instructions that, as written, will continue endlessly, unless an external intervention occurs, such as turning off power via a โ€ฆ Wikipedia
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Infinite_loop
Infinite loop - Wikipedia
January 2, 2026 - Modern interactive computers require that the computer constantly be monitoring for user input or device activity, so at some fundamental level there is an infinite processing idle loop that must continue until the device is turned off or reset. In the Apollo Guidance Computer, for example, this outer loop was contained in the Exec program, and if the computer had absolutely no other work to do, it would loop run a dummy job that would simply turn off the "computer activity" indicator light.
Discussions

php - What is the practical usage of Infinite loop : while(true)? - Stack Overflow
Does anyone know in which cases may infinite loop be useful in PHP? Example : More on stackoverflow.com
๐ŸŒ stackoverflow.com
June 6, 2024
Do we ever do this with real life examples?
Arikaturika Tumojenko is having issues with: Dave created an infinite loop in order to demonstrate the theory in this example, but do we ever do this in real life? I find linking the break ... More on teamtreehouse.com
๐ŸŒ teamtreehouse.com
1
May 4, 2016
What is the fastest and best way to do an infinite loop inside the main loop?
Someone once said that for(;;) is the best, some swear by while(1) It's purely a stylistic decision. This ain't Python, and all practical compilers trivially transform these to the same thing. (I personally prefer the former.) More on reddit.com
๐ŸŒ r/C_Programming
26
6
April 10, 2022
Loops in real life
Hey, So I just finished learning ... work in real life. Is this like when we take code challenges here on Treehouse and we see the "Bummer..." text if we miss a question? Do the programmers put every possible correct answer as a 'elseif' statement at the end of the loop and you can only proceed if you input one of those? Or is this all beyond where I am? Thanks! ... Loops have an almost infinite amount of ... More on teamtreehouse.com
๐ŸŒ teamtreehouse.com
1
April 4, 2015
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ infinite loop in c | types, causes, prevention (+examples)
Infinite Loop In C | Types, Causes, Prevention (+Examples)
October 17, 2024 - In C programming, infinite loops ... to continue indefinitely. Real-life Scenario: A hand dryer with a broken sensor continues to blow hot air even after the hands are removed....
๐ŸŒ
TechTarget
techtarget.com โ€บ whatis โ€บ definition โ€บ infinite-loop-endless-loop
What is an infinite loop (endless loop)?
In the attendance checking program example, the 26 students are listed in alphabetical order and labeled numerically, with the first student on the list being number one and the last student being number 26.
Published ย  February 7, 2023
๐ŸŒ
Quora
quora.com โ€บ What-are-some-funny-examples-of-infinite-loop-in-daily-life
What are some funny examples of infinite loop in daily life? - Quora
Answer (1 of 25): This is hilarious...Get in the loop! Man (Mr X) to his female assistant : We'll go out on a date tomorrow. Female assistant to her husband : I won't be coming home tomorrow so you can plan your day accordingly. Husband to his Girlfriend : My wife is not at home tomorrow. So you...
๐ŸŒ
Code
curriculum.code.org โ€บ csp-18 โ€บ unit5 โ€บ 11
While Loops
Infinite Loops: The final example in this activity guide produces an โ€œinfinite loop.โ€ This means that the computer (or person implementing the algorithm) will cycle through a set of commands forever, because the while loop condition is always true. Infinite loops are almost always undesirable, but they can be deceptively easy to create by mistake. Use the last portion of this activity to call out the fact that this is an infinite loop, that it is a very real possibility to make one in a program, and that they will have to be careful when making while loops since, as this example shows, it is fairly easy to create an infinite loop which prevents the rest of your program from running.
Find elsewhere
๐ŸŒ
Medium
rasiksuhail.medium.com โ€บ unraveling-the-infinite-exploring-the-mysteries-and-perils-of-infinite-loops-327d7f46d858
Unraveling the Infinite: Exploring the Mysteries and Perils of Infinite Loops | by Rasiksuhail | Medium
May 26, 2023 - Here's an example: for i in range(10): if i % 2 == 0: continue print(i) ... The continue statement is used to skip the even numbers and only print the odd numbers. Hereโ€™s a table comparing finite and infinite loops: Infinite Loops in Networking: ...
๐ŸŒ
Quora
quora.com โ€บ What-are-some-practical-uses-of-infinite-loops
What are some practical uses of infinite loops? - Quora
Answer (1 of 5): There are two common infinite loops in programming. The first is to ensure all input is obtained. The OS is an infinite loop which constantly checks for input and response accordingly. The second is when you need to do some calculating before you know the exit condition. The ...
๐ŸŒ
Codecademy
codecademy.com โ€บ forum_questions โ€บ 52f7ed9680ff33a93f0002d4
What happens in an infinite loop? | Codecademy
I messed up and I think it did an infinite loop, because when I pressed Submit the button stayed depressed, the browser said Not Responding and my computer started thinking hard.
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ python infinite loop | types, applications & more (+examples)
Python Infinite Loop | Types, Applications & More (+Examples)
October 25, 2024 - Infinite loops are useful in several scenarios, including: Event-driven programming: Waiting for user actions, such as in graphical user interfaces (GUIs) or servers that handle incoming requests.
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ what is the fastest and best way to do an infinite loop inside the main loop?
r/C_Programming on Reddit: What is the fastest and best way to do an infinite loop inside the main loop?
April 10, 2022 -

You know when you have options in your program and you have to to if-else argv argc stuff, and only THEN you actually go into the REAL infinite loop of your program.

How to do it? What is the best loop?

Someone once said that for(;;) is the best, some swear by while(1)

But then how do you (umm what's the word..) "exit gracefully" ? I've seen people having a variable like while (keep_looping), so they can get back to the main loop for cleanup and stuff and so they can return 0 or whatever other error code. But having a variable is obviously slower than just having 1 ? (what is even 1 in this case? a literal? either way it is definitely const and on the heap.)

Soo, what do you use? What should I use?

Top answer
1 of 10
16
Someone once said that for(;;) is the best, some swear by while(1) It's purely a stylistic decision. This ain't Python, and all practical compilers trivially transform these to the same thing. (I personally prefer the former.)
2 of 10
8
The "best" way to do this is likely an infinite loop and then a break statement wherever you detect the termination condition. I personally prefer while(1) because for loops should be used for count control and while loops should be used for logic control. Since a main program loop is almost always logic controlled it should be a while loop. With that in mind: I wouldn't fight someone on it. That's just how I chose one versus the other. But having a variable is obviously slower than just having 1 ? (what is even 1 in this case? a literal? either way it is definitely const and on the heap.) If the compiler implemented your code literally (without optimization) it could store the value 1 on the heap and then generate instructions to load that value into ACC (or your architecture's equivalent) and then jump if it is not 0. One optimization would be to just generate those instructions directly without loading from the heap: i.e. load ACC with 1 (the value 1 would be stored in the code section, not the data section) then jump if it isn't zero. The next optimization would be to remove the load entirely. The compiler can just unconditionally jump, which is obviously theoretically faster. In reality the branch predictor might handle this perfectly anyway.
๐ŸŒ
Oreate AI
oreateai.com โ€บ blog โ€บ understanding-infinite-loops-the-endless-cycle-in-programming-and-life โ€บ 9166beae578a8d25bb30b3049fdcc375
Understanding Infinite Loops: The Endless Cycle in Programming and Life - Oreate AI Blog
December 30, 2025 - while True: # Some task here if some_condition: break # Exit the loop based on condition ยท Hereโ€™s where humor meets reality: someone joked that breathing could be seen as an infinite loopโ€”we breathe continuously until we donโ€™t!
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ what is infinite loop in python?
What is Infinite Loop in Python? | Scaler Topics
May 8, 2024 - A real-life use case of the infinite loop can be the head and tails game. Various games need a toss (random selection of head or tail) that decides which team will start the game first (for example in a cricket game, the toss decides which team ...
Top answer
1 of 1
4
Loops have an almost infinite amount of uses. A loop is useful for any sort of task that requires iteration. Is this like when we take code challenges here on Treehouse and we see the "Bummer..." text if we miss a question? No. If there is an actual error with the loop, the code will break and the compiler will let you know, if there is one. But more often than this you'll run into logic errors, where the code runs fine but it isn't exactly doing what you intended for it to do. You can create issues that you don't realize are issues until months down the road. So in real life, there isn't always something to tell you that you're doing something wrong. There are practices and methods to combat this, which you will eventually learn. Do the programmers put every possible correct answer as a 'elseif' statement at the end of the loop and you can only proceed if you input one of those? It sounds like you're referring to a very specific loop / set of conditions. The programmer will make the exact amount of 'elseif' statements the program requires, there really isn't a set standard. For when the possible conditions are too great in number, then there are other ways of going about it without cluttering your code, but any method will essentially do the same thing. I don't think it's terribly common to have that many conditions for one statement, though. Remember that the uses of these tools, such as loops and conditions, are basically infinite. Existing loops and conditions that you'll run across will come in all sorts of different shapes, sizes, and configurations. You're still learning the concepts of how programming works. These sort of concepts will become much clearer to you as you continue learning. Try not to concern yourself with how coding works in "the real" world for now, focus on learning the tools and how you can use these tools to make the program do what you want. That is essentially real programming. Keep learning, and good luck!
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ cprogramming โ€บ c_infinite_loop.htm
C - Infinite Loop
When the program is run, it won't print the message "Hello World". There is no output because the while loop becomes an infinite loop with no body. The for loop in C is used for performing iteration of the code block for each value of a variable ...
๐ŸŒ
Code Snippets Wiki
codesnippets.fandom.com โ€บ wiki โ€บ Infinite_Loop
Infinite Loop | Code Snippets Wiki | Fandom
One common example of such situation is an e-mail loop. A pseudo-infinite loop is a loop that appears infinite but is really just a very long loop. ... It appears that this will go on forever, but in fact the value of i will eventually reach ...
๐ŸŒ
Gitbooks
buzzcoder.gitbooks.io โ€บ codecraft-javascript โ€บ content โ€บ while-loop โ€บ infinite-loop-and-break.html
Infinite Loop ยท CodeCraft - JavaScript - BuzzCoder
~ Start an infinite loop. ~ Get user input. ~ If input is 0, stop the loop. ~ If input is not 0, do math and continue the loop. ... In the above loop, the condition itself is true, so the computer will always continue running the loop. Now we need a way to exit the loop. This can be done with break keyword. break will cause the current loop to end, and the computer will jump to the code directly following the loop. Here is a good example of an infinite loop that works:
๐ŸŒ
LaunchCode
education.launchcode.org โ€บ lchs โ€บ chapters โ€บ loops โ€บ infinite-loops.html
6.9. Infinite Loops โ€” LaunchCode's LCHS documentation
By removing num += 1 from the loop body, the value of num remains 0. By changing the operator to num -= 1, the value of the variable decreases every iteration. By making either of these changes, the expression num < 21 will ALWAYS return True, so the while loop will NEVER stop.