Code:int x = 0;
if (x == 0)
{
x = 5;
...*lot's more code*... //why does this stuff execute?
}
Printable View
Code:int x = 0;
if (x == 0)
{
x = 5;
...*lot's more code*... //why does this stuff execute?
}
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.
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){}