Asp.net for loop statement page 1/2

Source: Internet
Author: User


The for loop format is:For ([initialization expression]; [condition expression]; [iteration expression ])
{
// Statement Block
}

Here, the [initialization expression], [condition expression], and [iteration expression] are optional. The [condition expression] must be a Boolean expression.

Perform the following steps:
Step 1: run the initialization expression only once.
Step 2: Start to execute the conditional expression (if it is null, return true). If it is true, execute the statement in braces; if it is false, directly jump to the end point of.
Step 3: start executing the iteration expression + condition expression.
Step 4: if the condition expression is true, execute the statement in braces and return Step 3. If it is false, the control point is switched to the end point of.

Here we will use multiple examples to deepen our understanding:
Example 1:

For (INT num = 1; num <0; num ++)
{
Response. Write (Num );
}

Result: null.
Cause: Execute int num = 1 first, then execute num <0; then num <0 returns false, exit the loop.

Example 2:

Response. Write ("Result: <br/> ");
For (INT num = 1; num <5; ++ num)
{
Response. Write (Num + "<br/> ");
}

In the third part, replace with: num ++ and the result is:

Cause: do not always confuse the I ++ and ++ I problems. Use them here, and do not write something similar to int I = 0; I = I ++; I = ++ I. What is I = I ++? It is equivalent to: int TMP = 0;
I = 1;
I = TMP;

You can write something to confuse yourself.CodeIs it necessary?

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.