I found a simpler version of Ben's do/while condition

42 PM

Here’s my simplified version, so as said by Ben a do/while always runs at least once, so all we need is PrintIntro and PlayGame to be ran once, after that we can use AskToPlayAgain’s true/false return value as a condition for the while condition.

Because AskToPlayAgain() returns a bool you can omit the == 1 check and just have while (AskToPlayAgain());

1 Like

Likewise, I had to make it that simple as well. -No idea how could Ben have missed it!

I instinctively went for the while (AskToPlayAgain()) solution as well and was surprised about the longer way Ben did it however I assume he does it this way for clarity. It’s easier to understand the code in Ben’s way and he is teaching us a standard way to label a bool with a b in front as well.

Perhaps Ben can clarify.

1 Like

I did it (AskToPlayAgain()) and it works just fine, noticed @ben did it his way and then questioned why he would take the long way round, if you notice onthe top of the video there is a bar that states he just prefers this way. As mentioned above I think it is just for clarity, but regardless both work just fine and in my head it seemed logical to just state the boolean already created rather than clutter up code and make a new variable.

Privacy & Terms