This is a question from a past exam paper.
Why does the loop invariant say i<=n when the loop test says i<n .
Is there a suitable answer: it says i<=n , how i will be equal to n in the failure condition in the while loop. Therefore, the 6th iteration i will be equal to the value of n 6 in the failure condition. However, the while loop itself points to i<n , since i starts at 0 and ends the cycle once i equals 5.
private int n =6; public int fact(){ int i = 0; int f = 1; while(i<n){
source share