Your first option, and probably what your teacher does not want you to do as it's generally frowned upon is to add a
break statement after you ask if they want to play again. It'll break you out of the
for loop.
The best option (not for just your teacher, but in general coding practice) is not to use a
for loop and
break statement. I would use a
while loop and do something like:
Code:
while(count < guess1 && !correct) {
// blah blah blah
}
The variable
correct would be a boolean storing
false normally, but would be set to
true if they get it right. The
count variable would be incremented within the loop if they get a wrong guess.
I would also either set
guess1 to 21 if they choose too many tries, or put that part in its own loop and make it loop until they pick a valid number.
-Shane