Code:int x = 0; if (x == 0) { x = 5; ...*lot's more code*... //why does this stuff execute? }
Code:int x = 0; if (x == 0) { x = 5; ...*lot's more code*... //why does this stuff execute? }
Well, there are a few things wrong with your code:
1) It does not work.
2) It does not work.
3) It does not work.
Hope this helps.
because an if statement executes everything in the block following it if the condition is true. The comparison is made before x is given a new value.
Away.
Ok, that's what I thought.
That will execute until x is given a new value before the statement, like
Now, if u didnt want it to execute you could aso edit the if condition as such:Code:x = 10;
Code:if (x != 0){}