while loop not working

Aug 31, 2011 at 9:14pm
When the code gets to this line and currentState->nextState does equal STATE_EXIT the loop runs anyways. What would cause this?

 
while( currentState->nextState != STATE_EXIT )


NOTE: I went through with the debugger so i know currentState->nextState equals STATE_EXIT when it gets there
Last edited on Aug 31, 2011 at 9:15pm
Aug 31, 2011 at 9:22pm
I can only think that the compiler may be treating the nextState variable as constant throughout the loop. This may happen if there is no explicit change of nextState in the code inside the loop. I guess you'll have to show more code, namely the code inside the loop.
Aug 31, 2011 at 11:06pm
Try to use a infinite loop.
1
2
while(true)
if(c u r r e n t S t a t e - > n e x t S t a t e ! = S T A T E _ E X I T) break;

So, can you show us more code?
Aug 31, 2011 at 11:17pm
@Tolga gerekci I'm sorry but this is a bad piece of advice, so bad you made me log in to comment, I'm sorry, but the only time the while(true) loop should ever be used is for dubugging purposes - that is testing your code, it should never be used for anything else, there should allways be a way out of any loop no matter how obscure.

For the original question I would like to know why you can actually perform this action inside your code, when rogramming remember encapsulation:
1
2
3
4
while(currentState->GetNextState() != STATE_EXIT)
{

}


but to answer your question I think we would need to see a little more code like what your doing before the loop and your definition of STATE_EXIT, thank you.
Topic archived. No new replies allowed.