Java notes (3): Java statement Loop Structure

Source: Internet
Author: User

This is one of the important skeleton of the Code. It is easy to use and you may not want to write this description at the beginning. However, it may be convenient for you to study your homework in the future. It is also okay to simply write it.

1. While statement, basic form: While (expr) stmt
Note: When the while statement is executed, the expr is first evaluated. If the result is true, the while statement is terminated when the cyclic body stmt is executed. If the value is false, the while statement is terminated, continue to execute the next statement of the while statement. After each execution of the stmt loop body, the conditional expression expr will be re-evaluated, and then the result determines whether to continue to execute the stmt or terminate the while statement.


While (expr)
...{
Stmt1
.....
Stmtn
}

 

2. Loop Control statementsBreakAndContinue

The break statement causes the control flow of the program to jump out of the loop and execute the next statement of the while statement. Note that executing break only exits the loop of the innermost layer, instead of the loop of the outermost layer.
The continue statement causes the next loop to be executed in advance.

3. do_while statement, basic form: Do stmt while (expr)
Note: the flow direction of the do_while statement is to first execute the loop body, and then determine the result of the evaluation of the conditional expression. If the result is true, the execution of the loop body continues, otherwise, end the loop and execute a statement.

4. Equivalent operations of while and

Int counter = 0;
While (counter <n)
...{
Stmt
Counter = counter + 1;
}

For (INT counter = 0; counter <n; counter = counter + 1) stmt

 

 

 

 

 

 

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.