I am super new to C # and programming in general. I am trying to do some exercises online to become familiar with the basics of the language before I start learning next month. I wrote a super-simple program, and I just can’t understand why she does what she does, and I could not find the answer anywhere. Here is the code.
int i, j, rows;
Console.Write("\n\n");
Console.Write("Display the pattern like right angle triangle which repeat a number in a row:\n");
Console.Write("-------------------------------------------------------------------------------");
Console.Write("\n\n");
Console.Write("Input number of rows : ");
rows = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= i; j++)
Console.Write("{0}", i);
Console.Write("\n");
}
All this program should do is a simple pyramid with the same number.
My question is that in the second cycle he writes i, but then reevaluates j++and j<=instead of recording \nuntil the end of the last run of the cycle. I do not understand why? The program works, but I do not understand why. Shouldn't a for loop always do everything in it unless you break it?
, !