0

Could someone explain clearly about this?

the output of the codes are different. That is: for(int x=1;x<=5;x++) { for(int y=1;y<=3;y++) { Console. Write("a"); } Console.WriteLine(); } Output : aaa aaa aaa aaa aaa That is 3a and five times loop running But when I put 'x' in inner most loop instead of '1' (int y=x; y<=3; y++) output : aaa aa a The output is different. x also equal to 1, y=x=1.So, why the output is different. That's really make me confuse.

22nd May 2018, 4:57 PM
Mr Thaw
Mr Thaw - avatar
3 Respostas
0
The difference is in the starting condition of the inner loop: First code: y always starts at 1, so it prints 3 "a" per line consistently. Second code: y starts at x, reducing the number of "a" in each line as x increases. Output: aaa aaa aaa aaa aaa vs. aaa aa a From x = 4 onward, the inner loop doesn't run, so no more output.
3rd Apr 2025, 5:55 AM
Jad Alghussin
0
Could someone explain clearly about this? the output of the codes are different. That is: for(int x=1;x<=5;x++) { for(int y=1;y<=3;y++) { Console. Write("a"); } Console.WriteLine(); } Output : aaa aaa aaa aaa aaa That is 3a and five times loop running But when I put 'x' in inner most loop instead of '1' (int y=x; y<=3; y++) output : aaa aa a The output is different. x also equal to 1, y=x=1.So, why the output is different. That's really make me confuse.
3rd Apr 2025, 1:07 PM
Ttper
Ttper - avatar