# Evaluating multiple lines of code inside a Do loop and extracting results

I'm trying to use NMaximize to maximize a function within a looped domain, and evaluate several different expressions at each of those solutions. What I'd like to do is get the following five lines of code:

Print[
NMaximize[
{Sqrt[s] + Sqrt[t] - x s - y t, 1000000 >= s >= 0, x >= 0},
{{s, 999, 1000}, t, x, y}]]
Extract[%, 2]
{s, x, t, y} /. %
3 s + 4 t^2 -3 x y
3 x + s^2 - t/y
{s, x, t, y} =.


To run within a Do loop of the form

Do[
{Print[
NMaximize[
{Sqrt[s] + Sqrt[t] - x s - y t, 1000000 >= s >= 0, x >= 0},
{{s, i 1000 - 1, i 1000}, t, x, y}]]},
{i, 10}]


I'd basically like it to return

• Solution 1
• Expression 1 @ Solution 1
• Expression 2 @ Solution 1
• Solution 2

And so on

• 1. Use Table instead of Do/Print 2. Use a (localized—see Module) variable instead of % 3. If you never assign to s, x, ... then there is never a reason to use =. on them. Commented Aug 7, 2017 at 9:51
• Notice that Maximize[Sqrt[s] + Sqrt[t] - x s - y t, {s, t, x, y}] returns that "The maximum is not attained at any point satisfying the given constraints". Are you sure your expression can be maximized appropriately? Commented Aug 7, 2017 at 14:33