So, I have C ++ code for feedback tracking nodes in the BFS algorithm. It looks something like this:
typedef std::map<int> MapType; bool IsValuePresent(const MapType& myMap, int beginVal, int searchVal) { int current_val = beginVal; while (true) { if (current_val == searchVal) return true; MapType::iterator it = myMap.find(current_val); assert(current_val != myMap.end()); if (current_val == it->second)
However, while (true) seems ... suspicious to me. I know this code works, and logically I know that it should work. However, I cannot shake the feeling that there should be some condition in while , but in fact the only possible way is to use the bool variable to tell if this has been done. Should I stop worrying? Or is it really a bad form.
EDIT . Thanks to everyone for noticing that there is a way around this. However, I would still like to know if there are other valid cases.
c ++ language-agnostic coding-style infinite-loop
rlbond
source share