0

I am in a big confussion. While loops

1. { static void Main(string[] args) { int num = 0; while(num++ < 6) Console.WriteLine(num); } it execute 6 times. begin with 1 and end with 6. 2. int num = 0; while(num < 6) { Console.WriteLine(num); num++; } it execute 6 times. but begin with 0 and end with 5. what is different between this two. Please explain me in brief.

15th Nov 2016, 1:59 PM
Habibur Rahman
Habibur Rahman - avatar
2 ответов
+ 4
in the first code when value of x reaches 5 it is checked whether it's incremented value that is 6 is smaller than 6 which is false and thus it does not execute but other when x reaches 5 it's checked if x that is 5 still is less than that its true and therefore execute one more time.
15th Nov 2016, 3:02 PM
Sandeep Chatterjee
0
Thanks a lot Sandeep Chatterjee. I really liked your Ans.
18th Nov 2016, 5:00 PM
Habibur Rahman
Habibur Rahman - avatar