0

Why did prefix override the condition?

static void Main(string[] args) { int num = 1; while(num < 6) { Console.WriteLine(num++); //output: 1 2 3 4 5 static void Main(string[] args) { int num = 1; while(num < 6) { Console.WriteLine(++num); /output 2 3 4 5 6 //why this 6, when the condition is <6

29th Dec 2016, 7:54 AM
Ajani AbdulGaniy A
Ajani AbdulGaniy A - avatar
1 Odpowiedź
+ 5
Lets focus on this : static void Main(string[] args) { int num = 1; while(num < 6) { Console.WriteLine(++num); } When num equals to 5, it can go into the loop right? Once it is inside the loop, it will print out (num + 1) because its a prefix. Hence, it will print out 6.
29th Dec 2016, 8:11 AM
Wen Qin
Wen Qin - avatar