0
Magic ?????? how does this happened ???
namespace SoloLearn { class Program { static void DrawPyramid(int n) { for (int i=1; i<=n; i++) { for (int j=i; j<=n; j++) { Console.Write("AB"); } for (int k=1; k<=2*i-1; k++) { Console.Write("*"+" "); } Console.WriteLine(); } } static void Main(string[] args) { DrawPyramid(2); } } } when you run the code "AB" string of the first loop is supposed to be written once but i nthe second loop it become two "AB" on the first line which was only one "AB" if we run DrawPyramid(1); !! how it becomes 2 please ???
1 Réponse
+ 2
If you post it so we can see it in the code playground would be better.
Looks like that code says the following:
DrawPyramid(2)
First iteration of first loop:
i=1 <= 2 TRUE
Go for the second loop, first iteration
j=i=1<= 2 TRUE
Write AB
go for the second iteration of second loop
j++ j now equals 2
2 <= 2 TRUE
Write AB again
j++ j now equals 3
j<=2 FALSE end of loop, next lines...
End next lines
Go to first loop and start the same process
i++, now i =2.
Etc
Hope it helps