This is a simplified version of something that came up in my code and I couldn't explain.
The code keeps writing 0 in the console output and never ends.
int test = 0;
while (test < 100)
{
test = test % 2 == 0 ? test++ : test + 2;
Console.WriteLine(test);
}
I understand that it's not necessary to assign anything to your variable when you use the ++ operator but I don't see how it would change the outcome either.
In my mind what should happen in the first loop is the following: The condition is met and test++ is executed but only after assigning its original value to test, since it's test++ and not ++test. So test is assigned a 0 and afterwards its value is incremented to 1.
But that's not what happens, it just stays 0 so what is actually happening here?