0

How does the logic in For loops work in C# ?

Here is the code for(int i =1;i <=5;i++) { for(int j =5;j >=i;j--) { Console.Write(j) ; } Console.WriteLine(); } The output will be 54321 5432 543 54 5 So, my qoustion is why the code still doing loop when int j >= i (2 >= 4)at 4th line. In my logic when 2>=4 the loop will only print the console.writeline() ; I hope you understand my code and my english. Thanks in advance.

25th Aug 2021, 6:36 PM
Wage
Wage - avatar
2 Answers
+ 3
On each iteration of i, the "j-loop" is entered anew. Look at int j = 5: j will always be resetted to 5 on each "i-interation"
25th Aug 2021, 7:11 PM
Lisa
Lisa - avatar
0
Thank you
26th Aug 2021, 10:00 AM
Wage
Wage - avatar