简体   繁体   中英

visual studio while loop suddenly stopping without completing all iterations

I'm working on visual studio 2010. Here I have a while loop and the code is as follows

while(cx!=ex && cy!=ey){
 //a* algorithm code inside
}

however after the 12th iteration the while loop suddenly breaks despite the condition remaining unfulfilled. There are no 'out of bounds' errors or anything like that. What could be causing this? What would be the best solution for this because I can say that there could be around a few to a hundred iterations. Thanks.

edit: code is in C++. Sorry.

Could you provide some more code? (C++?)
If you're using MACROS for example, you could have "hidden" Break statements, etc.
Have you debugged it? Put a break point after the loop and check the values of cx and cy

Since it's highly unlikely that the while loop suddenly stops with no reason I recommend you start by making sure that the while condition is really false.

You didn't state what language you're using, in C# you can use:

 Debug.Print(cx == ex);
 Debug.Print(cy == ey);

This should help you find the problem. If there is a problem in your code, one of them will return true

Update: For C++ the method is the same, check the values of the 4 variables right after the loop ends.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM