Different Implementation Without Do_While Loop

In the AskToPlayAgain() function, the professor simply returned the true or false value on whether Response[0] was equal to ‘y’ or ‘Y’. Then, he used those values in the main function with a do while loop. I implemented the loop already in the previous lecture and the way I did it is in the AskToPlayAgain function, instead of using:

return (Response[0] == ‘y’ || Response[0] == ‘Y’);

I used an if statement like so:
if ( (Response[0] == ‘y’ || Response[0] == ‘Y’){
}
return False;

and in the body I simply made a function call to main() which will loop back and start the main function again until the if statement becomes false and then just return False. Is this bad practice? I wanted to keep the main function as tidy as possible.

If your program works then it is ok.

However for beginners to programming who have not been introduced to if statements then it is not fine because you are chancing yourself as a teacher to teach them something new.

I hope you are clear on this.

Privacy & Terms