Exiting While loop

Oct 7, 2012 at 5:55am
I'm working on code for a program and am stuck trying to cleanly get out of my loop. Here's the code:


I'm trying to figure out a way out of the loop with out having the cout show up again. I'm sure I'll probably figure it out in the morning with a fresh nights sleep but will take any suggestions. I still need to clean the code up a bit too.
Last edited on Oct 7, 2012 at 11:14pm
Oct 7, 2012 at 8:48am
while(hit!=9)
maybe this is the problem... could you post your full code?
Oct 7, 2012 at 9:01am
Maybe indentation is problem.
Oct 7, 2012 at 9:42am
like chipp said, please post your full code.
Oct 7, 2012 at 9:56am
add the line cout<<hit<<endl; at the end of the loop so you can see what happens with your hit var .
Last edited on Oct 7, 2012 at 9:56am
Oct 7, 2012 at 1:27pm
You could change line 20 to

1
2
if ( ++hit == 9 )
    break; 


Of course, then there's no reason to have a loop condition at all. Better would be to structure the loop so that the block of code you currently have after the if/else if construction is above it, perhaps in a do/while loop.
Topic archived. No new replies allowed.