# How to sort the "do" output?

So I have function (FindCoefficients) that iterates through some values to find the maximum value for a function. It is much quicker to hold the non-linear values constant and do a find maximum for the linear coeffiecients then to do a non linear optimization for a complicated function.

This is the main line that I'm struggling with:

Do[Print[a , b, FindCoefficients[a, b]], {a, 1, 10, 1}, {b, 1, 10, 1}]


This gives me the output of

11{value of maximum, other info}

12{value of maximum, other info}

13{value of maximum, other info}

...

21{value of maximum, other info}

...

1010{value of maximum, other info}

Is there any way to sort my output from greatest to smallest, so I can easily pick out the maximum?

• Use Table, not Do. Then you can Sort. You might find parts of this a useful reading: mathematica.stackexchange.com/q/134609/12 Jun 3, 2019 at 8:00

SortBy[ Table[{a , b, FindCoefficients[a, b]} , {a, 1, 10, 1}, {b, 1, 10, 1}],{3}]