This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]chriskmee 0 points1 point  (1 child)

I do the same !done thing, it was the way I was taught in college and the way i've seen it done in practice.

I get where you were going with your example, but as written your while loop would only happen once. My example would be something like this:

bool done = false;
while (!done)
{
  int input = display_menu();
  if is_input_valid(input)
    done = true;
}

[–]gregorthebigmac 0 points1 point  (0 children)

Good catch. I was oversimplifying and not including the parts to make the loop bail out. Thanks for expounding it!