Hi there,

I have only just began the proccess of learning C# Programming (this week)returning to education as a mature student, one of the assessments I have been given is to find out how to, and then write a program using 'nested for loops' to display the 1,2,3 and 4 times tables. I do not want someone just to write the code for me to copy as this would be of little value to the learning proccess, but would greatly apprieciate any member of the forum being able to point me in the right direction of how I can begin to solve this problem.

I imagine it will require two loops the first being: for (int i=1; i<5; i++) this to give the 1 to 4 times tables ??
The second loop is where I am at a total loss (providing it does just require two loops and the first is correct).

I apprieciate for many this this will be very basic, and apologise if I have posted this to a forum it does not belong.

nested loops are loops within loops

``````for(outer=1; outer<4; outer++){
for(inner=1; inner<5; inner++){
//do something here ...
}
}``````

in the sample:
first iteration: outer = 1, inner = 1
second iteration: outer = 1, inner = 2
third iteration: outer = 1, inner = 3
fourth iteration: …

@daniel955
Your outer loop goes from 1 to 3, the OP wants it from 1 to 4.
The inner loop should probably go from 0 to 9

## All 5 Replies

nested loops are loops within loops

``````for(outer=1; outer<4; outer++){
for(inner=1; inner<5; inner++){
//do something here ...
}
}``````

in the sample:
first iteration: outer = 1, inner = 1
second iteration: outer = 1, inner = 2
third iteration: outer = 1, inner = 3
fourth iteration: outer = 1, inner = 4
fifth iteration: outer = 2, inner = 1

as you can see, the outer loop increments only when the inner loop is done
and when the outer loop increments by 1, the inner loops starts again at 1

commented: Well explained! +7

@daniel955
Your outer loop goes from 1 to 3, the OP wants it from 1 to 4.
The inner loop should probably go from 0 to 9

``````Console.WriteLine("This displays the one to four times tables");
for (int a = 1; a <=4; a++)

{
for (int j = 0; j <= 12; j++)
{
Console.WriteLine(a * j);
}``````

many thanks for taking the time to help, the code above is what I have come up with so far and it gives out a display of the tables in a single column; what i was wondering is, can it be displayed to show a format like :
1x0=0
1x1=1

Yes, experiment with Console.Write and Console.WriteLine and some formatstrings.
Example: Console.Write("{0} x {1} = {3}", a, j, a*j);
This "{0} x {1} = {3}" is called a format-string the {0} etc. in it, are placeholders for the arguments a,j and a*j.