When I start my code
for (byte i = 0; i < 1000; i++) {
System.out.print(i);
}
I get infinite loop. Why?
When I start my code
for (byte i = 0; i < 1000; i++) {
System.out.print(i);
}
I get infinite loop. Why?
Simply because byte value starts to overflow after its max value i.e. 127
.
The value of i
will go up to 127
and then will overflow to -128
and then increment back to 127. This process will therefore never satisfy your for loop termination condition, and thus loop forever.