asp.net for loop statement 1th/2 page _ Basic Application

Source: Internet
Author: User

The format for the For loop is:
for (initialization expression; conditional expression; "Iteration representation")
{
Statement block
}

Where: "Initialization expression", "conditional expression", "iteration representation" is optional, and "conditional expression" must be a Boolean expression.

The steps to perform are:
Step one: Start the initialization expression and execute it once.
Step two: Start the conditional expression (return true if null), and if true, execute the statement in curly braces, or false, and skip to the end point for.
Step three: Start the execution of the iteration representation + conditional expression.
Fourth step: If the conditional expression is true, the statement in the curly braces is executed, the third step is returned, and if False, the control point is transferred to the end point for.

Here are a few examples to deepen our understanding:
example one:
for (int num = 1; num < 0; num++)
{
    Resp Onse. Write (num);
}

Result: null.
Reason: Perform int num = 1, then num < 0, then num < 0 returns false and exits the loop.

example two:
Response.Write ("Result: <br/>");
for (int num = 1; num < 5; ++num)
{
    Response.Write (num + "<br/>"); The third part of
}

is replaced by: num++ The result is also:


Reason: Don't always be confused by the i++,++i problem, use it here, and don't write like int i = 0;i = i ++;i = ++i. i = what is i++? It is equivalent to:
int tmp = 0;
i = 1;
i = tmp; 

Do you need to write code that you can all get mixed up with?
current 1/2 page   1 2 Next Read full text
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.