sentinel and counter controlled loops? what?

does anyone know a good way to explain these?
counter controlled loop is a loop that does something n times.

sentinel controlled loop is a loop that looks at the input and decides whether to continue or not.
counter controlled:
 
for(int index = 0; index < 100; ++index) {} // will loop 100 times 


sentinel controlled:
1
2
3
std::ifstream in("myfile.txt");
std::string tmp;
while(std::getline(in,tmp)) {} // will loop until the end of myfile.txt 
That's not a sentinel controlled loop. To be a sentinel controlled loop, it would need to check for a sentinel value in the input.
Topic archived. No new replies allowed.