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
1 Answer
+ 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.