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
5
votes
6 answers

Infinite loops using 'for' in Python

Why does this not create an infinite loop? a=5 for i in range(1,a): print(i) a=a+1 or this for i in range(1,4): print(i) i=i-1 or this for i in range(1,4): print(i) i=1 Is there any way we can create infinite loops using a for loop?…
Nischal
  • 53
  • 1
  • 1
  • 7
5
votes
0 answers

Infinite loop using AndroidKeyStore authentication

My application enters an infinite loop when I use the AndroidKeyStore requiring user authentication to use the keys .setUserAuthenticationRequired(true); .setUserAuthenticationValidityDurationSeconds(60); It is assumed that an operation that uses a…
pedrofb
  • 37,271
  • 5
  • 94
  • 142
5
votes
1 answer

How to detect and stop an infinite loop in user-provided JavaScript code?

I am writing an in-browser code editor for games. The editor will allow users to write their own JavaScript files, which are then loaded into the same DOM that the editor is running on. This will allow them to see the game in a canvas element next…
Michael Auderer
  • 507
  • 5
  • 12
5
votes
10 answers

What is the difference between for(;;) and while(1)?

Possible Duplicate: Is “for(;;)” faster than “while (TRUE)”? If not, why do people use it? I was wondering what is the difference between for(;;) and while(1) when both perform same function? Will there be any difference of speed of compilation
abhinav
  • 151
  • 4
  • 11
5
votes
2 answers

JAVA : Why does the following infinite loop terminate without any error / exception

I was messing around with stuff in my eclipse when, to my surprise, I found that this piece of code when run gets terminated without any error / exception public class Test { public static void main(String[] args) { for(int i = 2; i > 0;…
Ray
  • 59
  • 1
  • 5
5
votes
9 answers

How to get nested array length in Javascript?

I have an example of nested array: var testArray = [1,2,[3,4,[5,6],7],8,9,[10,11],12]; Here is my function for getting nested array length: Array.prototype.getLength = function() { var sum = 0; function getMultiLength(array) { for (count =…
5
votes
3 answers

while(true) loop without break

I am quite new to Java programming. For now I am studying source code of an android app called Evercam. However, I have a problem understanding a part of the code which involves while(true) loop. Here is the snippet of the code: while (true) { …
daisura99
  • 1,030
  • 1
  • 12
  • 22
5
votes
2 answers

Will an infinite 'while loop' consume excessive resources

I want to trigger a Java code at specific timing, let say every morning 1 AM. I write a thread as below: while (true) { if (currentTime = 1AM) { doSomething; } } I am a bit worry, the while loop keep running, will it slow…
Sam YC
  • 10,725
  • 19
  • 102
  • 158
5
votes
1 answer

Detecting loops in tree structures (graphs)

I'm writing a library which is configured using a recursive structure. For the sake of this discussion I'm calling these graph structures a "tree" since there is a defined "root" node and each node can refer to more than "child". When properly…
Philip Couling
  • 13,581
  • 5
  • 53
  • 85
5
votes
8 answers

Java - Endless loop with ListIterator .hasNext()

ArrayList list = new ArrayList(); list.add("test"); while(list.listIterator().hasNext()) { System.out.println(list.listIterator().next()); } This generates an endless loop of lines with "test". Why does this happen and how to…
Nik
  • 179
  • 1
  • 3
  • 11
5
votes
2 answers

List of integers and infinite loop in Prolog CLPFD

Suppose I want to represent integers like so: integer:Sign:[FirstDigit,SecondDigit,...]. For instance, 42 would be represented as integer:positive:[4,2]. I need a predicate that generates the value of the integer based on this representation and…
Fatalize
  • 3,513
  • 15
  • 25
5
votes
2 answers

JavaScript prevent infinite loop - possibily with dynamic recognition pattern?

first of here is the commented pseudo-code: // TODO: // Person A (80kg) nutrition intake requirements are: // nutrient || Unit(g) // Vitamin A : 30, // Vitamin B1 : 2, // Vitamin C : 300, // Vitamin D : 3000, // Protein …
noa-dev
  • 3,561
  • 9
  • 34
  • 72
5
votes
2 answers

List manipulation leads to infinite loop

I am trying to create an array for listing purposes in Ionic Framework and check all the callcenter name's first char to add them in an alphabet array. for (var i = 0; i < callcenterList.length; i++) { var value = callcenterList[i]._owner &&…
Yagiz
  • 1,033
  • 2
  • 21
  • 47
5
votes
3 answers

killing an infinite loop in java

I am using a third-party library to process a large number of data sets. The process very occasionally goes into an infinite loop (or is blocked - don't know why and can't get into the code). I'd like to kill this after a set time and continue to…
peter.murray.rust
  • 37,407
  • 44
  • 153
  • 217
5
votes
5 answers

What is wrong with this Java GUI code?

I've just started learning Java GUI and faced this problem while practicing event handling. Here's the initial window When I enter a number inside the text field it's supposed to say whether the guessed number is higher, lower or matched. If not…