Do While Loop in C#
- January 6, 2025
- Posted by: admin
- Categories:
No Comments
/* In the do while loop, the condition is checked after exectution of a certain block of code.In the example below, we want the user to enter a positive number, but as long as they do not do that, i.e the condition in the while loop is true, the loop will continue until a point when the loop is false, meaning the user has entered a positive number, that’s when the loop will end */
int number;
do
{
Console.WriteLine(“Enter a positive whole number”);
number = int.Parse(Console.ReadLine());
} while (number <= 0);
Console.WriteLine(“Finally!”);
Console.ReadKey();