do-while loops test the expression after the statement block has executed - CSharp Language Basics

CSharp examples for Language Basics:do while

Introduction

ensuring that the block is always executed at least once.

Here's the preceding example rewritten with a do-while loop:

Demo Code

using System;/*from   w  ww . j  a va2 s. c  o  m*/
class Test
{
   static void Main(){
      int i = 0;
      do
      {
         Console.WriteLine (i);
         i++;
      }
      while (i < 3);
   }
}

Result


Related Tutorials