class kk{
public static void main(String args[]){
int n=0;
for (byte i = 0; i<=255; i++)
{
n++;
}
System.out.println(n);
}
}
The above for loop goes on infinitely . I would appreciate it if somebody could answer why ?
Because byte values are in the range of
[-128, 127].Hence, when the byte 127 is incremented it overflows to -128 and your loop continues indefinitely.