C # Select Structure statement and Loop statement

Source: Internet
Author: User

1. Select Structure Statement

C # Selection Structure statement is mainly

if (judging condition) {

1

}

else{

2

}

Returns true when the condition in the if is satisfied execution 1, only if the condition in the if is not satisfied to return false execution 2

For example:

2. Looping statements

The loop statement is mainly divided into: While statement for statement Do...while statement These three kinds (for most commonly used)

(1). While statement

while (loop condition) {

1

}

How to meet the loop condition is always circulating (while thestatement is prone to form a dead loop )

This while is a dead loop.

(2). Do...while statements

do{

1
}

while (loop condition)

This statement is the same as the previous while statement

The difference is that the do...while is executed first 1 in the execution loop condition, while the while is the first execution of the loop condition in execution 1 (Do...while statement also easy to form a dead loop )

This statement is also a dead loop

(3) for loop (most commonly used)

For (initialize an expression; loop condition; action expression) {

1

}

This cycle is most commonly used (it is not as easy to form a dead loop as the two loops above)

This statement is not a dead loop.

(4). Loop inside can be set loop

For example:

3. Jump statements

It's mainly a break,continue.

(1). break

Jump out of the loop when executing to the break statement

Jump out of the loop when you're i=4

(2). Continue

When executing to the Continue statement, jump out of this loop

Jump out of this loop when you're i=4.

(3).

Continue and break they're the same way.

C # Select Structure statement and Loop statement

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.