ASP.Net/Language Basics/While Loop

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

While Loop Demo (C#)

   <source lang="csharp">

<%@ Page Language="C#" debug="true"%> <script runat="server"> void Page_Load() {

   Random objRandom = new Random();
   int  DiceRoll = 0;
   byte bytRollCounter = 0;
   while (DiceRoll != 6){
       if(bytRollCounter%3 == 0 && !(bytRollCounter==0))
       {
           Message1.Text += "   Keep trying! 
"; } bytRollCounter +=1; DiceRoll = Convert.ToInt32(objRandom.Next(6)) + 1; Message1.Text += "Rolled a: " + DiceRoll + "
"; }

} </script> <html> <head>

   <title>Modulo example (using a While Loop)</title>

</head> <body>

   <asp:label id="Message1" runat="server"></asp:label>

</body> </html>

      </source>