Apt condition to stop in i and j directions(x,y directions)