Summary
Your goal was to use the do-while
and while
statements to perform iterations. The do-while
and while
statements are unique because the body of the code block determines whether the flow of execution should continue or stop.
Using the do-while
statement, you executed a block of code once before evaluating a Boolean expression and potentially exiting the iteration. Using the while
statement, you performed the evaluation of the Boolean expression immediately, and continued to evaluate it to exit the iteration. You used the continue
statement within the code block to step directly to the Boolean expression.
You developed a practical application that uses the do-while
and continue
statements to simulate a battle in a role playing game. Real-world scenarios involving the do-while
and while
iteration statements involve working with streams of data from files, from the internet, or any other scenario where you'll continue to perform an iteration until a condition is met.
Without do-while
and while
iteration statements, it would be difficult to write and maintain iteration code that sets the exit condition within the iteration code block.
Get a free verified certification
Microsoft and freeCodeCamp.org offer a training and certification combo on foundational C#. By completing this Learn module, you've already started. Explore freeCodeCamp's Foundational C# with Microsoft certification here: https://aka.ms/csharp-certification.