C # Learning Notes (Process statements)

Source: Internet
Author: User

1 goto statement

C # allows you to tag lines of code so that you can jump directly to them using a goto statement. The advantages and disadvantages of this statement coexist. The main thing is this: this is an easy way to control when to execute what code. The main drawback is that excessive use of this technique will make the code difficult to understand.

Goto <labelName>

23-tuple operator

<test>?<resultIfTrue>:<resultIfFalse>

Where calculation <test> can get a Boolean value, the result of the operation is determined by this value is <resultIfTrue> or <resultIfFalse>.

3 If statement

If statement has more functions, it is an effective decision-making way. Unlike the?: statement, the IF statement has no result (so it is not used in an assignment statement), and the statement is used for conditional execution of other statements.

4 Switch statements

The switch statement is very similar to the IF statement because he is also conditionally executing code based on the value of the test, but the switch statement can compare the test variable to more than one value at a time, instead of just testing a condition. This test is limited to discrete values, not clauses such as "greater than X", so his usage is a bit different, but he is a powerful technique.

Switch <testVer>

{

Case <comparsonVal1>

{

<Code>

Break

}

  

Case <comparsonVal2>

{

<Code>

Break

}

  

Case <comparsonVal3>

{

<Code>

Break

}

Defualt:

<Code>

Break

}

5 Do...while ... Statement

int i = 1;

Do

{

console.wirteline{"{0}", i++};

}while (I < 10);

This example loops 10 times to print the 1~10 number

6 While statement

while (<Test>)

{

<code to be looped>

}

With Do...while ... Statement is different, the while statement is the first to judge the execution

7 For Loop statement

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

{

<code to Loop>

}

8 Interrupts in the loop

8.1 Break-immediately interrupts the loop and jumps out of the loop body

8.2 Continue-immediately interrupts the current loop and resumes execution of the next loop statement

8.3 goto-can jump out of the loop to the already marked position

8.4 Return-jumps out of the loop and its included functions

C # Learning Notes (Process statements)

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.