Can a for loop be written in Java to create an infinite loop or is it only while loops that cause that problem?
Can a for loop be written in Java to create an infinite loop or is it only while loops that cause that problem?
There's lots of ways to make for loops infinite. This is the solution I found:
int j = 1;
for (int i = 0; i < j; i++) {
//insert code here
j++;
}
This works really well for me because it allows the loop to check an infinite amount of values as well as looping infinitely.