added nested loop end for range condition