do
{
    //execute code block

} while(boolean expression);
  1. The do-while loop executes the block of code repeatedly.
  2. 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.
  3. Use the break keyword to stop the execution and exit from a do-while loop.
  4. 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);
Last modified: June 24, 2019

Author

Comments

Write a Reply or Comment