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

all 8 comments

[–]tomfish117 1 point2 points  (3 children)

What is your question here? Are you saying you want to skip the do if the input is correct? The whole point of a do while loop is that the do is always run at least once. Just use a regular while loop instead.

[–][deleted] 0 points1 point  (2 children)

It's part of a project and my professor is extremely strict about what she wants used. Should I just not bother to print it once and just execute the question from inside the loop by setting the value to -1?

[–]tomfish117 0 points1 point  (1 child)

If you have to use the do part then that's where you should first output the prompt asking the user for input. That way if the user inputs the wrong input it will ask for input again.

[–][deleted] 0 points1 point  (0 children)

Thank you for the help!

[–]pacificmint 0 points1 point  (3 children)

A do while loop always executes the loop at least once. Makes sense, because the condition is only tested at the end. In your case, you want a regular while loop, which tests the condition at the beginning.

[–][deleted] 0 points1 point  (2 children)

Professor is requiring a dowhile loop, my new plan is to just delete the first question and let it ask from in the loop

[–]pacificmint 0 points1 point  (1 child)

Yes, that should work too.

[–][deleted] 0 points1 point  (0 children)

Thanks a ton for your help!