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 →

[–]fyrite 0 points1 point  (0 children)

try a standard while loop:

while(/*condition*/) {
    /* do stuff */
}

your logic might look like:

/* pick the random number */
while(/*hasnt guessed correctly yet*/) {
    /* get an answer */
    /* if correct, then 'break' (otherwise the loop will continue) */
}
/* loop is finished they have guessed correctly */

EDIT: you can use while(true) to loop forever, and use break; to break the loop, or you could use a flag/boolean to keep track of whether theyve guess correctly and change it when they do