"Rookie also crazy C # series"--Process Control

Source: Internet
Author: User
Tags case statement

The previous two blogs about C # class fields and the definition of class methods, this blog mainly talk about C # control structure, and VB similar, using C # and VB to learn this part of the method.


First, C # control structure



Second, VB control structure


Third, Comparison

C # in the control structure and VB is still very similar, the basic structure is generally consistent, just a few grammatical differences.


Select

in C # in the If condition judgment statement, it is not like VB, but also write the end if this statement, directly write if ... else, or if......elseif ... You can do it. But I always feel so awkward, may be accustomed to the VB Grammar bar, feel that there is no end if, it is not executed as finished.

However, the switch break statement in C # is similar to the Select Case statement in VB, except that the select is replaced with a switch, and after each conditional judgment, the add-on statement is added. Check the dictionary, switch is switch, switching, switching, and so on, but here I feel it is the meaning of switching, each select one, it switches once, after execution, and jump to another. The syntax is as follows:


switch (expression)

{

Case constant expression:

Statement Series 1

Break

......

Case constant expression:

Statement Series N

Break

Default

Statement Series n+1

}

The difference between a switch and an if statement in C # is that switch is judged by a specific value, and if is judged by scope.


Loops

C # 's looping statements are similar to VB, with For,while loops. The difference is that the FOR Loop statement in C # does not have a next,while loop, but it is also executed in the all while statement, similar to the Do loop while in VB.

C # also contains the Foreach Loop statement, which is not in VB, and is similar to the FOR Loop statement, which is used primarily to iterate over the elements in the collection.


Jump

Jump statements are used for unconditional transfer control. In C #, the jump statement includes the break and continue statements in addition to the goto statements in VB.

The break statement is primarily used to terminate the most recent enclosing loop or the switch statement in which it is located.

The continue statement is primarily used to skip other parts of the loop body, and forcing the program to advance into the iteration of the loop is essentially a complement to the break statement.

The goto statement functions in C # similar to that in VB, and can be unconditionally transferred to other program segments.


Iv. Summary

Through the comparison of C # and VB control structure of learning, found that the language is actually the same, but the grammar is not the same only, and let me associate with the software engineering flowchart, each structure can be drawn into a flowchart, the basic logic can be cleared. Because there are too few instances of knocking, some statements have not really realized its role, and hope to understand their role better when learning design patterns.



"Rookie also crazy C # series"--Process Control

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.