While loop re-initiates itself!
Hi All,
I've created a while loop which, once the condition is satisfied, stops. But then a few lines later if the condition is "unsatisfied", the while loop decides to reinitiate itself.. I'll show you what I mean:
Code:
bool is_line_valid()
{
//Return true if there is a new line character after the last #
list<char>::iterator list_iter = row_chars.end();
while(*list_iter != '#')
{
list_iter--;
}
cout << "Finished while loop; print what is at current container: " << *list_iter << "\n";
cout << "Now move container forward (to last position)... \n";
list_iter++;
if(*list_iter == '\n')
return true;
else
return false;
}
And here's the output (perpetual of course):
Code:
Finished while loop; print what is at current container: #
Now move container forward (to last position)...
Finished while loop; print what is at current container: #
Now move container forward (to last position)...
Finished while loop; print what is at current container: #
Now move container forward (to last position)...
..etc.
Can someone tell me why this happens please?