My solution for Do/While lecture 28 (want to confirm if it's okay or not)

So I was doing the challenge and came up with this code :

 int main() 
{
	do
	{
		PrintIntro();
		PlayGame();

	} while (AskToPlayAgain());

	return 0; //exit application
}

I was quite surprised watching the rest of the video and seeing we need to add another boolean, is there any downside for what I did? Testing the programs there seems to be no problems, but maybe for future coding?

Thank you :slight_smile:

I did the same. Can some confirm that’s ok? I was quite suprised that it worked actually. Didn’t think that function will run normally when put into the condition of a loop.

1 Like

Yes that is what I decided to go with because as the program is reading top down, that called function still has to be evaluated to either true or false before reaching the while part of the condition. However, good practice may go against it.

1 Like

When I did the challenge I used this code.

int main() {

	bool bPlayAgain = false;
	do {
	PrintIntro();
	PlayGame();
	}
	while (bPlayAgain = AskToPlayAgain());

	return 0;
}

It worked. I didn’t run into any problems but I am wondering if this can work or will run into problems down the line?

Yup same. The additional bool variable is eventually getting fed by the AskToPlayAgain function anyways. I thought this would be easier. So even i’m not sure if that was done as good coding practice or to add more context.