Findkeyframe Command

Hi!
Can't make work this code correctly

CODE
string $sel[] = ls -sl -transforms;
string obj;

  for($obj in $sel)
  {

int $ini_f =findKeyframe -timeSlider -which next;
int $fin_f =findKeyframe -timeSlider -which previous;

        string $kfRange2 = ($ini_f+":"+$fin_f);
        print ($kfRange2+"\n");

   }

there is few objects. Each of this objects have 2 kayframes in different frame. Objective is to get frames that have keyframes and insert : symbol between.
loop returns selections last objects values.

Find next keyframe works on a selection set. The flag -timeSlider is intended for the timeline view querry change so it can not be passed individual objects in bigger selection without wasting considerable time.

CODE
{
  string $sel[] = ls -sl -transforms;
  string $obj;

  for($obj in $sel)
  {
    int $ini_f =findKeyframe -animation objects -which next $obj;
    int $fin_f =findKeyframe -animation objects -which previous $obj;
    string $kfRange2 = ($ini_f+":"+$fin_f);
    print ($kfRange2+"\n");
  }
  //select -r $sel;
}

PS: put code inside CODE

 and QUOTE

tags its a bit hard to show it in this foum properly because those tags turn into tags

Thanks Joojaaa !
I've just founded the solution too ) .

CODE
string $sel[] = ls -sl -transforms;
string $obj;

   for($obj in $sel)
  {

select $obj;
int $ini_f =findKeyframe  -time 0 -which next;
int $fin_f =findKeyframe  -time 48 -which previous;

        string $kfRange2 = ($ini_f+":"+$fin_f);
        print ($kfRange2+"\n");

   }

In this case I nee 2 value more. First one indicates 1 frame of time range and second one last frame but I choose yours

Its always faster to pass selections to the commands than to select and act on that. Because managing the selection s quite heavy thing and needs undo too and that wastes memory.