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
11
votes
2 answers

Updating state to the same value directly in the component body during render causes infinite loop

Let's say I have this simple dummy component: const Component = () => { const [state, setState] = useState(1); setState(1); return
Component
} In this code, I update the state to the same value as before directly in the…
Tehila
  • 917
  • 4
  • 19
11
votes
3 answers

Usability of infinite loop in Rust

Rust contains loop, which is specially designed for infinite looping: Using the keyword loop, Rust provides a way to loop indefinitely until some terminating statement is reached (like program exit) I can't think of a single scenario when I…
Fusion
  • 5,046
  • 5
  • 42
  • 51
11
votes
3 answers

Spring Boot - infinite loop service

I want to build a headless application which will query the DB in infinite loop and perform some operations in certain conditions (e.g. fetch records with specific values and when found launch e-mail sending procedure for each message). I want to…
Pawel Urban
  • 1,316
  • 1
  • 12
  • 28
11
votes
5 answers

Validate the type of input in a do-while loop

Basically, I need to ensure that input is an integer, like so: do { printf("Enter > "); scanf("%d", &integer); } while (/* user entered a char instead of an int */); I have tried various methods, but it always end up with run-time error or…
Juen Khaw
  • 161
  • 1
  • 1
  • 10
11
votes
1 answer

Laravel 5 redirect loop error

I trying to make a login and admin script, the problem is that I have a redirect loop I dont know why. I want the login users and can be in the / path not /home. If change return new RedirectResponse(url('/')); to return new…
user4012084
11
votes
4 answers

why does an infinite loop of the unintended kind increase the CPU use?

I know an infinite loop to the unintended kind usually causes a high CPU usage. But, I don't quite understand why. Can anyone explain that to me?
user342673
  • 624
  • 2
  • 8
  • 17
11
votes
5 answers

How for( ; ;) is infinite loop?

Like many other question explained that while(true) {} is an infinite loop and so is for( ; ;) my question is while(true) makes sense the conditions is always true but there is no vivid condition true/false in for( ; ;) so how is the later an…
user2009750
  • 3,169
  • 5
  • 35
  • 58
11
votes
2 answers

angularjs infinite $digest Loop when no scope changes

I'm getting the below error in my angular code. I'm struggling to understand why the function getDrawWithResults would cause a digest cycle as there don't seem to be any side effects? It just returns items from a list that have a property set to…
foiseworth
  • 951
  • 2
  • 11
  • 19
11
votes
1 answer

Custom layout UITableViewHeaderFooterView

So I just tried subclassing UITableViewHeaderFooterView and aligning the labels the way I want by overriding -layoutSubviews. When I call super and change a label's frame, however, the app appears to be stuck in an infinite -layoutSubviews loop. My…
Christian Schnorr
  • 10,768
  • 8
  • 48
  • 83
11
votes
5 answers

Chess: Getting All Legal Chess Moves

I am making the game chess, and have gotten virtually everything but one thing: I need to make it so that it is impossible for a player to move a piece into check. I am having trouble on how to tackle this problem. What I have right now in…
Mike
  • 241
  • 1
  • 4
  • 11
11
votes
1 answer

What could cause an Android activity to relaunch itself infinitely when returning from camera?

I have a weird bug in my application that causes an activity to relaunch itself in an infinite loop when I'm returning from a camera application, after taking a picture. The UI flow is like this: Main Activity -> Accept Photo activity -> in…
Corneliu Dascălu
  • 3,900
  • 1
  • 28
  • 38
10
votes
4 answers

C exit from infinite loop on keypress

How can I exit from an infinite loop, when a key is pressed? Currently I'm using getch, but it will start blocking my loop as soon, as there is no more input to read.
user196106
10
votes
5 answers

When running user inputed Javascript, is there a way to detect and stop "problem" scripts?

On a page, something like jsFiddle, that executes user inputed Javascript, is there a way to stop / disrupt "problem" scripts running in an iframe? The major class of problem scripts would be infinite loops, I think. Browsers deal with multiple…
Peter Ajtai
  • 56,972
  • 13
  • 121
  • 140
10
votes
2 answers

how to handle code that never executes

I have some code that looks like this and I'm unsure how to handle the part which will never get executed since a part of this code runs in infinite loop while waiting for connections and when I terminate the program, it exits from there…
Abhinav Gauniyal
  • 7,034
  • 7
  • 50
  • 93
10
votes
7 answers

Strange "for(;;)" infinite loop in Java, how is this useful?

Though I have some experience in Java, the following code looks a bit strange to me: public class ForLoopTest{ public static void main(String[] args){ for(;;){} } } This code compiles fine, although the initialization-test-increment…
Razib
  • 10,965
  • 11
  • 53
  • 80