# How I can go to a new line in a nested For-loop?

How I can go to a new line in the following code:

M = 2;
L = 2;
For[n = 1, n <= M, n++, For[k = 0, k <= L, k++, Print[u[n, k] = n*k]]]


I want to go to a new line after running the inner loop. Can I use \n?

I want to have:

Any suggestions?

• @Karsten 7 I want to have new line, for this code I want to have 0 1 2 and the new line 0 2 4. May 31 '17 at 19:25
• What are your actual goals here? The approach you've chosen in unlikely to match your goals. In a notebook, print adds a cell to the notebook.
– Alan
May 31 '17 at 19:43
• probably better to make a Table and use MatrixForm or TableForm May 31 '17 at 19:48
• Scan[Print[# Range[0, 2]] &, {1, 2}] May 31 '17 at 19:54
• If you are really intent on "printing" individual items and somewhat controlling the format you can use WriteString[$Output,expr] with "\n" as needed for line breaks. I'd really encourage you not to try to write c in mathematica though. May 31 '17 at 21:22 ## 2 Answers Avoiding For, ApendTo(1)(2), and GraphicsGrid: Grid[ Array[Times, {2, 3}, {1, 0}], Spacings -> {4, 1} ] $\begin{array}{ccccc} 0 & \text{ } & 1 & \text{ } & 2 \\ 0 & \text{ } & 2 & \text{ } & 4 \\ \end{array}\$

Perversion of "\n" (StringRiffle):

StringRiffle[Table[i j, {i, 1, 2}, {j, 0, 2}], "\n", "\t"]