C-Language Process control structure-cyclic structure

Source: Internet
Author: User

Loop structure

Cyclic structure-while

while (condition)

{

Statement

}

Explanation: First determine whether the condition is established, the establishment of the execution, after the execution of the code again to determine whether the condition is established (judging conditions-"code block-" Judgment conditions-"execution code block ...) )

1. First determine the operation of the loop (loop in vivo statement)

2. In determining the constraints, that is, the number of cycles required (cyclic body judging conditions)

3. Define a variable to record the number of cycles (defined as needed or undefined)

Tip: use If...break (jump out of the loop) or If...continue statement in the while loop (jump out of the loop to continue the next loop).

Loop structure-do while

Do

{

Statement

}while (condition)

Features: ADo While loop performs at least one loop body

Cyclic structure-for

For (statement 1, condition, statement 2)

{

Loop body

}

Statement 1: Typically an initialization statement

Statement 2: Typically an incremental statement (a statement executed after the loop body is executed)

"Contrast" for and while:

On the performance, the for loop slightly better because the while loop can use only external variables, and for loops to recycle variables in a timely manner.

Tips: Two code implementations of the Dead loop: while (1) for (;;)

C-Language Process control structure-cyclic structure

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.