Chapter 6th circular Structure (ii)

Source: Internet
Author: User

(1) The syntax format for the For loop structure is as follows.

for (expression 1; expression 2; expression 4) {

Loop body

}

Expression 1: The initial part of the loop structure, assigning the initial value to the loop variable.

Expression 2: Loop condition of the looping structure.

Expression 3: The selected part of the looping structure, usually used to modify the value of the loop variable.

(2) Circular structure summary

different syntax:

The while loop structure statement is as follows:

while (condition) {

Loop body

}

The DO-WHILE loop structure statement is as follows:

do{

Loop body

}while (< conditions >);

The For Loop structure statement is as follows:

for (initialize; condition; select) {

Loop body

}

The execution order is different:

while loop structure: The condition is judged first, then the loop body is executed. If the condition is not true, exit the loop.

Do-while Loop structure: The loop body is executed first, then the loop is judged, and the loop body is executed at least once.

For loop structure: first executes the initialization part, then carries on the condition judgment, then executes the loop body, finally carries on the calculation of the selection part, if the condition is not established, jumps out the loop.

different application conditions:

In case of problem solving, the for loop structure is usually chosen for the number of cycles determined. For cases with uncertain cycle times, the while and do-while loop structures are usually chosen.

(3) In a loop, you can use the break and continue statements to control the flow of the program.

The break statement is used to terminate a loop, and the program jumps to the next statement outside the loop body.

The continue statement is a statement used to jump out of this loop and into the next loop.

Chapter 6th circular Structure (ii)

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.