I'd like to use an infinite loop in Java: for (;;)
and I think it would look amusing if I could replace that ';;'
with the variable 'ever'
like this:
String ever = ";;";
for(ever){
...
}
Is such a thing possible in Java?
To answer your question, an alternative would be to use a Set and check that its size is the same as the array length after you inserted all the array's elements into it (or check on the fly). By efficienty you change the complexity of the algorithm from O(n^2) to O(n) but you use (at most) O(n) extra space.
An infinite while loop in Java is a set of code that would repeat itself forever, unless the system crashes. At a certain point, the data becomes an overload and the program will overflow. This means it will fail.
You can break any loop using break; . If your program is already listening for keyboard input, you just need to put that break command inside a conditional statement that checks for the desired input.
No it is not possible.
The closest you can come is this:
final boolean ever = true;
for (;ever;) { }
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