do
{
//execute code block
} while(boolean expression);
- The do-while loop executes the block of code repeatedly.
- The do-while loop execute the code at least once. It includes the conditional expression after the code block and the increment/decrement step should be inside the loop.
- Use the break keyword to stop the execution and exit from a do-while loop.
- An nested do-while loop is allowed.
int i = 0;
do
{
Console.WriteLine("Value of i: {0}", i);
i++;
if (i > 5)
break;
} while (true);
Comments