As recommend in comments, better to use Table or Do.
how I can get the value of S1 for each i value in the output.
For For
you can still use Sow
and Reap
as well
result = First@Last@Reap@For[i = 1, i <= 3, i++,
For[j = 1, j <= 3, j++,
Sow[{i, j}]
]
]

to show the name of the variable in the output (e.g: S1 =
{{1,2},{2,3}}) and not just {{1,2},{2,3}}?
What do you mean by show S1={...}
? In Mathematica x=1
is assignment, and Mathematica displays back 1
, not x=1
. To show x=1
you would need to force things into strings. Something like
("S = " <> ToString[#]) & /@ result

an example with Table application
result = First@Last@Reap@Do[
Do[
Sow[{i, j}]
,
{j, 1, 3}
],
{i, 1, 3}
]

Or to make it do something more interesting
result = First@Last@Reap@Do[
Do[
Sow[{ Row[{"S[", i, ",", j, "]=", i + j}], i + j}]
,
{j, 1, 3}
],
{i, 1, 3}
];
And now the actual computation result is stored in result[[All,2]]
and the display part is stored separately in result[[All,1]]
result[[All, 2]]

result[[All, 1]] // Column

Print["S1=" <> ToString@S1];
$\endgroup$Table
what the OP wanted (95% of questions that contain "loop" in its title). (result = Table[<<bla>>,{i,1,10},{j,1,10}]
). (This post could be an exception, though...). $\endgroup$