Place your declaration for i
at line 3 so that the loop becomes an infinite loop.
public class Puzzel3 {
public static void main(String[] args) {
// Line 3
while (i == i + 1) {
System.out.println(i);
}
System.out.println("done");
}
}
Basically, the infinite loop happens when the condition in the while loop always evaluates to true. This can happen when the variables within the loop aren't updated correctly, or aren't updated at all. Let's say you have a variable that's set to 10 and you want to loop while the value is less than 100.
We can create an infinite loop using while statement. If the condition of while loop is always True , we get an infinite loop.
An infinite loop is a looping construct that does not terminate the loop and executes the loop forever. It is also called an indefinite loop or an endless loop. It either produces a continuous output or no output.
Do While loop While loop has a condition like while loop. We can make place the same always true statement to make an infinite loop.
Math says, that Infinity + 1 == Infinity, so
// The declaration required
double i = Double.POSITIVE_INFINITY;
// It's infinite loop now...
while (i == i + 1) {
System.out.println(i);
}
System.out.println("done");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With