While Loop Demo (C#) : While Loop « Language Basics « ASP.Net






While Loop Demo (C#)

<%@ 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! <br>";
        }
        bytRollCounter +=1;
        DiceRoll = Convert.ToInt32(objRandom.Next(6)) + 1;
        Message1.Text += "Rolled a: " + DiceRoll + "<br />";
    }
}

</script>
<html>
<head>
    <title>Modulo example (using a While Loop)</title>
</head>
<body>
    <asp:label id="Message1" runat="server"></asp:label>
</body>
</html>

           
       








Related examples in the same category