jeudi 26 mars 2015

C++ Will all code inside a nested 'if' statement run, even if that changes the boolean value of the outside statement?

I have a couple of if statements in my C++ code (one nested inside the other), and I want to be sure that they will run as I expect- the code is:



if(state == entry){
if(abs(distance < 0.05){
state = arcing;
...
startAngle = positionAC;
}
// Some more statements here...
}


If the second if statement condition is met, will the code where my comment "// Some more statements here..." be run now that the value of state has changed to arcing rather than entry? I would have thought that they should be run because the code will still be executing from when the first condition was true, even though it now no longer will be. Is this correct?


Aucun commentaire:

Enregistrer un commentaire