① While statement
When the value of an expression is true, this statement executes a statement list. Control
The Boolean expression of the while statement is enclosed in parentheses, followed by the while keyword. Brackets
The following statements are executed when the Boolean expression value is true.
The following is an application example of the while statement:
Int I = 1;
While (I <6)
{
Response. Write ("I value:" + I. ToString (). Trim () +
"<Br>");
I ++;
}
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<Html>
<Head>
<Title> Loops tutorial </title>
<Script runat = "server" language = "C #">
Void Page_Load ()
{
Int counter = 0;
While (counter <= 10)
{
MessageLabel. Text = counter. ToString ();
Counter ++;
}
}
</Script>
</Head>
<Body>
<Form runat = "server">
<Asp Tutorial: Label id = "messageLabel" runat = "server"/>
</Form>
</Body>
</Html>
② Do statement
This statement executes its nested statement zero or multiple times. If
If the expression value is false, no nested statement is executed. However, to ensure nesting
You can use a do statement to execute a statement at least once.
The do statement is followed by a nested statement followed by a while keyword.
The Boolean expression that controls the number of loop executions is behind the while keyword. Because cloth
The expression is evaluated after the nested statement is executed. Therefore, the nested statement is executed at least once.
.
The following is an application example of the do statement:
Int I = 1;
Do
{
Response. Write ("I value:" + I. ToString (). Trim () +
"<Br>");
I ++;
} While (I <6 );
Do while
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<Html>
<Head>
<Title> Loops </title>
<Script runat = "server" language = "C #">
Void Page_Load ()
{
Int counter = 0;
Do
{
MessageLabel. Text = counter. ToString ();
Counter ++;
}
While (counter <= 10 );
}
</Script>
</Head>
<Body>
<Form runat = "server">
<Asp: Label id = "messageLabel" runat = "server"/>
</Form>
</Body>
</Html>