The first statement gives n the range 0,1,2,3 (4 numbers beginning with 0, not 0 to 4)
The else statement is executed when the loop is finished. The last iteration of the loop is when n=3. The loop returns the 2. When the loop is exited and the else statement is executed, n is still 3, and that is what the last statement prints.