Brief analysis of the For loop in Java

Source: Internet
Author: User
Tags variable scope

For loop syntax format:
for (initialize; Boolean expression; update) {
Statement
}
(empty; empty; empty) {
Statement
}
Express conditions directly, directly execute the loop body, will be infinite loop)
Process:
1: Initialization is performed first and only once (declaring and initializing any loop control variable) (This can leave blank, but semicolon is required)
2: Computes the Boolean expression, if I true, the loop body will be executed, if it is false the loop body will not execute, the control flow will jump to the next statement outside the For loop body
3: After the For loop body is executed, it jumps to the UPDATE statement (this statement allows us to update any loop control variable) (here we can leave blank, but required semicolon is required)
4: The Boolean expression is judged again, if true, the loop body executes, then updates again, and then judges until the end of the false,for loop
Caveats: Variable scope: Want to have scope outside the For loop, then declare it outside the loop

Friendship Association:

About the choice of for, while, Do/while: the number of known cycles is used for, unknown sequential times with while and do/while (if it is to be executed before judging by Do/while)

Brief analysis of the For loop in Java

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.