I would like to save these 9 lines repeated in my code:
for (int n1 = 1, n2 = 1; n2 < 11;){
Console.Write(n1 + "x" + n2 + "=" + (n1 * n2) + "\t"); n1++;//1
Console.Write(n1 + "x" + n2 + "=" + (n1 * n2) + "\t"); n1++;//2
Console.Write(n1 + "x" + n2 + "=" + (n1 * n2) + "\t"); n1++;//3
Console.Write(n1 + "x" + n2 + "=" + (n1 * n2) + "\t"); n1++;//4
Console.Write(n1 + "x" + n2 + "=" + (n1 * n2) + "\t"); n1++;//5
Console.Write(n1 + "x" + n2 + "=" + (n1 * n2) + "\t"); n1++;//6
Console.Write(n1 + "x" + n2 + "=" + (n1 * n2) + "\t"); n1++;//7
Console.Write(n1 + "x" + n2 + "=" + (n1 * n2) + "\t"); n1++;//8
Console.Write(n1 + "x" + n2 + "=" + (n1 * n2) + "\t"); n1++;//9
Console.WriteLine(n1 + "x" + n2 + "=" + (n1 * n2)); n2++;//10
n1 = n1 - 9;
}
It is a simple for
loop that generates the multiplication table complete, the code is repeated 10x, each Console.Write
writes a column excerpt on the same line per repetition. I thought of nesting a for
within another, such as:
for (int n1 = 1, n2 = 1; n2 < 11;){
Console.Write(n1 + "x" + n2 + "=" + (n1 * n2) + "\t"); n1++;//9x
for (n1==10){
Console.WriteLine(n1 + "x" + n2 + "=" + (n1 * n2)); n2++;//1x
n1 = n1 - 9;
}
}
In this syntax, numerous errors emerge from Expected ...
I found this article C # - Nested Loops , but none resolved. Any solution?