Do while loop until the random number is six - CSharp Language Basics

CSharp examples for Language Basics:do while

Description

Do while loop until the random number is six

Demo Code

using System;// w w w. j  a v  a  2  s  . c om
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
   static void Main(string[] args)
   {
      // Random number generator
      Random randomNumbers = new Random();
      // Throwing as long as we have six
      int thrown;
      do
      {
         thrown = randomNumbers.Next(1, 6 + 1);
         Console.WriteLine(thrown);
      } while (thrown == 6);
   }
}

Result


Related Tutorials