C + + Fifth lesson loop structure

Source: Internet
Author: User

Loop structure:

One, while statement

While statement notation: while (expression) statement

Function: Executes the statement repeatedly (the loop body) until the expression is not established.

When the loop body is multiple statements, the compound statement ({...}) is used.

Second, for statement

For statement notation: for (expression 1; expression 2; expression 3) statement

Pay particular attention to the use of loop control variables, which are variables that determine the number of cycles executed:

Be sure to assign an initial value. (expression 1 for a For statement is called an assignment of an initial value expression, typically used to assign an initial value to a loop variable)

It is usually necessary to make a correction when the loop body is executed. (Expression 3 for the For statement is called a fixup expression, modifying the loop variable)

Third, break statement

The break statement is used within a loop statement or a switch statement.

The function is to jump out to the next statement.

Iv. Continue statements

The continue statement is used only in the loop body. The function is to end the loop, which is to skip the following statement that has not been executed in the loop body, and then proceed to the next execution of the loop (for the For statement, evaluate the expression 3).

C + + Fifth lesson loop structure

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.