Questions tagged [infinite-loop]

An "infinite loop" is a loop in which the exit criteria are never satisfied; such a loop would perform a potentially infinite number of iterations of the loop body. The general problem of determining whether the execution of a loop with given preconditions will result in an infinite loop is undecidable; in other words, there is no algorithm to determine whether an execution of a loop will eventually terminate. This is known as the halting problem.

3528 questions
24
votes
1 answer

Infinite 100% CPU usage at java.io.FileInputStream.readBytes(Native Method)

I'm right now debugging a program which has two threads per one external process, and those two threads keep on reading Process.getErrorStream() and Process.getInputStream() using a while ((i = in.read(buf, 0, buf.length)) >= 0) loop. Sometimes when…
Esko Luontola
  • 73,184
  • 17
  • 117
  • 128
23
votes
3 answers

how to declare i and j to make it be an infinite loop?

while( i <= j && i >= j && i != j) {} how to declare i and j to make it be an infinite loop ? // it's an interview question I met. it's asking what's the declarations of i and j, make it be always true. And I cant make it out by declaring i and j…
Alan
  • 497
  • 1
  • 3
  • 9
23
votes
4 answers

Creating an infinite loop

I'm trying to create an infinite loop, where a block of code will be executed forever. All loop documentation I have found warns against creating an infinite loop, but no examples of a working one. If I have a block of code: { puts "foo" puts…
Andrew Walz
  • 890
  • 2
  • 8
  • 27
23
votes
4 answers

Java: break statement in "if else"

I keep getting an error, if without else. I tried else if as well for (;;) { System.out.println("---> Your choice: "); choice = input.nextInt(); if (choice==1) playGame(); if (choice==2) loadGame(); if…
John
  • 2,015
  • 5
  • 23
  • 37
23
votes
9 answers

How to get out of while loop in java with Scanner method "hasNext" as condition?

I ran into an issue. Below is my code, which asks user for input and prints out what the user inputs one word at a time. The problem is that the program never ends, and from my limited understanding, it seem to get stuck inside the while loop. Could…
davidx1
  • 3,525
  • 9
  • 38
  • 65
22
votes
2 answers

Is infinite loop still undefined behavior in C++ if it calls shared library?

It's said that infinite loop for(;;); is undefined behavior. From http://en.cppreference.com/w/cpp/language/memory_model In a valid C++ program, every thread eventually does one of the following: terminate makes a call to an I/O library…
cshu
  • 5,654
  • 28
  • 44
21
votes
1 answer

Python - A keyboard command to stop infinite loop?

Possible Duplicate: Why can't I handle a KeyboardInterrupt in python? I was playing around with some Python code and created an infinite loop: y = 0 x = -4 itersLeft = x while(itersLeft<0): y = y + x itersLeft = itersLeft - 1 print…
PhillipKregg
  • 9,358
  • 8
  • 49
  • 63
21
votes
5 answers

Post increment operator not incrementing in for loop

I'm doing some research about Java and find this very confusing: for (int i = 0; i < 10; i = i++) { System.err.print("hoo... "); } This is never ending loop! Anybody has good explanation why such thing happens?
Michał Kupisiński
  • 3,765
  • 1
  • 19
  • 23
19
votes
4 answers

'while' statement cannot complete without throwing an exception - Android

With this method I'm updating TextView every second. private void UpdatingTime(final String endTime, final long diffInDays) { new Thread(new Runnable() { @Override public void run() { …
KiKo
  • 1,668
  • 7
  • 27
  • 56
18
votes
1 answer

Continue debugging in GHC after interrupt

I have a nonterminating expression in Haskell. I want to debug and inspect the reason why it is not terminating. A technique I learned is to use the following in GHCi: :set -fbreak-on-exception :trace nonterminating_expression ^C :hist 50 So I can…
Boldizsár Németh
  • 1,847
  • 13
  • 20
17
votes
5 answers

Stopping an infinite loop on a remote server PHP

I have a simple infinite for loop looking like this: set_time_limit (0); for (;;) { ... //Doing some stuff including to write to a file sleep(300); } It's running on my server. (Shared hosting account) How on earth can I stop it?
Pangolin
  • 7,284
  • 8
  • 53
  • 67
17
votes
1 answer

Asyncio, await and infinite loops

async def start(channel): while True: m = await client.send_message(channel, "Generating... ") generator.makeFile() with open('tmp.png', 'rb') as f: await client.send_file(channel, f) await…
user8245289
  • 173
  • 1
  • 1
  • 7
17
votes
5 answers

Running a BackgroundWorker continuously

I need to be able to continuously run my BackgroundWorker. The DoWork event contains a pool threaded process and the OnComplete updates my UI. I have not been able to find a way to infinitely loop the BackgroundWorker.RunWorkerAsync() method without…
16
votes
3 answers

NodeJS memory consumption in an infinite loop

I don't know if this is a bug with Node or V8, but if I run the following code the node process leaks memory. The GC never seems to kick in and in a few seconds it's consuming >1GB of memory. This is unexpected behavior. Am I missing…
Matty
  • 33,203
  • 13
  • 65
  • 93
16
votes
3 answers

For loop with no parameters in Java

I am looking at somebody else's code and I found this piece of code: for (;;) { I'm not a Java expert; what is this line of code doing? At first, I thought it would be creating an infinite loop, but in the very SAME class this programmer uses…
Doug Molineux
  • 12,283
  • 25
  • 92
  • 144