Why condition for skipping page is not working properly?