Question: Multiple subroutine with for-do loops

I am trying to write a program that contains multiple subroutine calls. I understand the placement of the single for-do loop to call the "lowest value" subroutine.

Here is program.

main := proc( x :: Vector)			 

   local n, k, y, value_min, index_min;
   n := LinearAlgebra[Dimension](x); 
   y := x[1..n];	 				 

   for k from 1 to n-1 do
      value_min, index_min := lowestValue(y,k,n);		 
      y[index_min] := y[k]; y[k] := value_min;		 
   end do;

   return y;
end proc;

lowestValue := proc( y :: Vector,k :: integer,n :: integer) 
   local value_min, index_min, j;
   index_min, value_min := k, y[k];

   for j from k+1 to n do
      if evalf(value_min) > evalf(y[j]) then
         index_min, value_min := j, y[j];
      end if;

   end do;
   return value_min, index_min;
end proc;

I also need to do this subroutine within main program
highestValue := proc(s)
   local i, n, value_max, index_max;

   n := LinearAlgebra[Dimension](s);
   value_max := evalf(s[1]); 
   index_max := 1;

   for i from 2 to n do 
      if evalf(s[i]) > value_max then 
         value_max := s[i];
         index_max := i;
      end if;
   end do;
   return value_max, index_max;

end proc;

Please Wait...