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.
Questions tagged [infinite-loop]
3528 questions
1
vote
2 answers
scanner.hasNext() results in an infinite loop
I have a piece of code which should read input word by word and add the length of the word to an ArrayList recursively (for a school exercise).
I wrote this method:
ArrayList wordLengths = new ArrayList();
Scanner scanner = new…

Jochem Kuijpers
- 1,770
- 3
- 17
- 34
1
vote
3 answers
Infinite loop in haskell
So I am writing a program to generate a list of prime numbers in haskell. I create two functions shown below:
{-
Given a list of prime numbers, this function will
add the next prime number to the list. So, given the
list [2, 3], it will return [2,…

user1654089
- 11
- 1
- 2
1
vote
4 answers
C++ Won't exit do while loop
I've just started learning C++. I am currently using Bloodshed Dev C++. dI'm creating a very basic and simple Rock Paper and Scissors Game. Everything in the program is working correctly except for the exit loop. Here is my code:
/* FILE…

Richard Paulicelli
- 129
- 3
- 6
- 23
1
vote
3 answers
infinite loop fscanf string textfile c programming
Why is that when I scan a string in the text file it always goes into an infinite loop?
while(val = fscanf(stdin,"%lf%c",d,c) != EOF)
{if(val==0){//error}
else if(c='\n'){//error print char}
else{//print double}
}
Text file:
4.5
r5
23
s
What I…

Poldz Kerk
- 69
- 3
- 15
1
vote
1 answer
how can I detect infinite loop when cout doesn't work?
I implemented the Edmonds–Karp algorithm in C++ and when I went to test it with a small graph, it didn't finish, but I can't identify where it got stuck. I usually use cout with something until I find where it prints infinitely, but I didn't work…

user2748531
- 1,213
- 4
- 12
- 21
1
vote
4 answers
Infinite loop code in C
In the below program I try to input a number between 1 to 100 but if I enter a 'character' or "string" ( like s or sova ) during the execution time of scanf() statement it creates a infinite loop. so I try to do .... when I input a string or a…

Minuddin Ahmed Rana
- 1,084
- 1
- 15
- 27
1
vote
1 answer
Button stuck, need to break infinite loop in java
I am writing a program that will move the mouse a certain distance in a given time period. So I need the algorithm to go as:
Click start
while(true){
move mouse to point x
sleep for n seconds
}
Which works, but when ran as a thread the…

Ducksauce88
- 640
- 3
- 12
- 26
1
vote
2 answers
Controlled infinite loop uses too much resources
I'm working in a part of a bigger project, that has to read from a lot of FIFOs and redirect them properly, depending on the commands. To achieve this, the FIFOs are read in order, in an infinite loop.
The problem is that it consumes too much…

markmb
- 852
- 4
- 12
- 32
1
vote
0 answers
drbl : virtual machine node fals to infinite boot loop
I run Debian linux.
I want to make a virtual machine in virtualbox, wich boots from a server via drbl.
The server will be my laptop.
The virtual machine start booting, but fall into infifite boot-loop.
It load one part of the OS from the server,…

Roger
- 11
- 1
1
vote
4 answers
Why an Infinite Loop
I've been learning C++, and this chunk of code is from a simple grading program. But when I try to get the user input, there's a problem.
If I enter a number, whether it be less than 0 or more than 100, or anything in between, my loop works…

NewtoProgramming
- 35
- 3
1
vote
1 answer
Force user to input integer - not catching errors
What is the indented lines directly below try: called/reffered to? I have heard "the body of try:" and "the expression of try:". Please clarify. (See user - poke´s - answer)
What is try:, except:, while: etc. reffered to? Like True and False are…

Progrmming is fun
- 17
- 5
1
vote
3 answers
Entering in an infinite loop while reading a file
This code accepts student name, father's name, roll no and age from input file and put it in a presentable manner in output file.
In this code, when contents of input file are:
Vicky
Mohan
20094567
22 Ricky
Rahul
20091234
21
It works fine.
But if…
user2655324
1
vote
2 answers
Kill an infinite-loop thread in java
Is there any way I can stop a thread without using deprecated stop()?
The thread invokes some methods from a potentially badly written class which may contain infinite loops. Since I can't modify this class, I have no control over the loop condition…

Bastien
- 658
- 1
- 9
- 24
1
vote
1 answer
infinitive loop at the end of action method
Recently I have faced with a very strange problem. My Action method must return JsonResult,and all is good untill the last break point before return (At this moment I have correct json result).Then in browser console I see error 500 (Internal server…

user2586558
- 59
- 1
- 6
1
vote
4 answers
Why is this code an infinite loop?
Before completing this code, I just tested it by mistake and realized that it will not stop:
$var = "any";
for ($i=1; $i < 2; $i++){
$var.$i = "any";
}
Why does this produce an infinite loop? And why doesn't PHP produce an error?
user1646111