Let's look at the following day-to-day example of Java.
package loop;
final public class Main
{
public static void main(String[] args)
{
long temp=1000000000;
while(temp--!=0)
{
temp-=temp++;
System.out.println("Inside loop = "+temp);
}
System.out.println("Outside loop = "+temp);
}
}
In the above simple code, the while loop iterates over only once though the local variable temp of type long contains a large value which is 1000000000.
Through the statement System.out.println("Inside loop = "+temp);, it displays Inside loop = 0 and through this statement System.out.println("Outside loop = "+temp);, it displays Outside loop = -1. Why is it so?
while(temp--!=0)gets executed once more before the loop is terminated