0
C# Making a Pyramid
How do the for loops work in the C# "Making a Pyramid" lesson? This is the code: static void DrawPyramid(int n) { for (int i=1; i<=n; i++) { for (int j=i; j<=n; j++) { Console.Write(" "); } for (int k=1; k<=2*i-1; k++) { Console.Write("*"+" "); } Console.WriteLine(); } } static void Main(string[] args) { DrawPyramid(5); }
1 Answer
+ 2
The best way that you can find out yourself is by adding some other outputs in each loop.
You could put an output with "for loop i" at the beginning, see where it begins/ends.
See if that starts to show you what's going on.