sorted loop