Can a for loop be written in Java to create an infinite loop or is it only while loops that cause that problem?
Just for fun (and this too long for a comment): a lot of people will be very surprised to learn that for a lot of very practical purposes the following is nearly an infinite loop:
for (long i = Long.MIN_VALUE; i < Long.MAX_VALUE; i++) {
...
}
If the thread executing this loops can do 4 billions cycles per second and can do the increment and the check in one cycle (quite beefy for a single thread) and if my maths ain't totally off, I think the above code needs about 150 years to execute : )