Asp. NET knowledge re-carding (iv)------about Process Control statements

Source: Internet
Author: User

Learning C language, we have learned the process of control statements, that is, the order, conditions, circulation three kinds. The first few flow control statements in the Tiobe programming language leaderboard seem almost identical, so say follow,

That's the truth.

First, sequential execution statements: As the name implies, in order to execute sequentially

Second, conditional statement:

1.If-else Statements

1, only contains if keyword, no else case:

           if (expression)
Statement1

2. If the branch containing if and else is the case:

           if (expression)
Statement1;
Else
Statement2;

3. Cases that contain multiple else if statements:

           if (expression1)
Statement1;
else if (expression2)
Statement2;

else if (Expression3)

Statement2;

......

Else

Statement

2.switch-case statement (indicating that the year when the C language used to see this knowledge point in the morning to understand)

       switch (<testVar>)
{
Case <comparisonval1>:
< statements executed when <testVar> equals <comparisonVal1> >
Break ;
Case <comparisonval2>:
< statements executed when <testVar> equals <comparisonVal2> >
Break ;
...
Case <comparisonvaln>:
< statements executed when <testVar> equals <comparisonValN> >
Break ;
Default:
< If there are no <comparisonValX> statements that are executed with <testVar> matching >
Break ;
}

      When the value in the case is equal to the value of the expression in parentheses after the switch, the switch statement exits when the break statement is executed, and if the value of the expression in the parentheses is not equal to the constant expression after all cases, then the statement following the default is executed and the switch statement is exited

        The most confusing thing about this statement

          Case <comparisonval1>:

Case <comparisonval2>:

Case <comparisonval3>:

< if <testVar> equals the statement executed at any of the three values above >
Break

        In such a case, three cases are common to one execution statement.

Third, the Loop statement:

1. Do loop: Executes the code marked as a loop, then performs a Boolean test, executes the code again if the result of the test is true, and exits the loop when the test result is false.

          Do

{

<code to be looped>

}while (<Test>)

2. while loop: Like a Do loop, unlike the Do Loop, a Boolean test in a while loop occurs at the beginning of the loop, not the last.

          while (<Test>)

{

<code to be looped>

}

3. for Loop: The main master is the process of the For Loop initialization->condition-> the statement in the execution loop that satisfies the condition,->operation-> the next loop; If the condition is not met, the statement in the loop is skipped directly.

          for (<initialization>;<condition>;<operation>)

{

<code to be loop>

}

        In C #, the foreach statement is very popular, and the foreach statement executes the loop body once for each element in the array or object collection

foreach (type identifier in expression)
{
Staterment
}

       Example: foreach (var arr in arrs)

{

var++;

}

The function of each number plus one in the array arrs (the var keyword here can replace any type, the compiler will judge the specific type according to the context, the person who learns JavaScript should be familiar with it), do not need to calculate the length of the array like for the For loop.

  Iv. Interrupt Statements

1.Break: Terminate the loop immediately

2.continue: Immediately terminates the current loop (resumes execution of the next loop)

3.goto: Can jump out of the loop immediately, to the marked position (as if the role of C language pointer, but in Java and C # These security high-level languages, goto statement is not recommended to use)

4.return: Jump out of loops and included functions

The topic of break and Continue is that beginners are bound to encounter, jumping out of a single cycle and jumping out of the entire loop body after understanding will not be confused. Goto statement If you want to study, but it is not recommended, I remember that C + + seems to have a goto statement, probably the same, but with a lot of it will make the program obscure, even the situation of the death cycle. And the return statement, may be more familiar to you, just beginning to learn the C language function, the last sentence of the int main () function is always return 0, and void main () function is not required; Later I summed up the functions (Java and C # As long as the type is not a void type, it must have a return value, or it will be an error.

This section of this article references the content in http://blog.sina.com.cn/s/blog_4c83c6bf01000823.html

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.