Java Looping statements

Source: Internet
Author: User

One, JAVA Process Control

Conditional Statement-if: Syntax format-if (single condition) as

Conditional Statement-if...else ... (Two choice one)

Conditional Statement-if...else If ... (multiple selection), can nest multiple else if

Conditional Statement-switch
Syntax Format-switch
switch (expression)
{
Case value 1: statement block 1
...
Case Value N: statement block n
Default: statement block n+1
}
Conditional Statement-switch (description)
The value of an expression can only accept int, Byte, char, short, enumeration, JDK1.6 string can also, do not accept other types of values, do not allow duplicate case value
When switch encounters the first case match, the program jumps to the tab location
Start the execution of all subsequent program code, regardless of whether the following case conditions match, until the break statement is encountered
Second, the circular statement
While:while (conditional expression)
{
EXECUTE statement block
}

Do...while:do
{

Executes the statement block;

} while (conditional expression);

For:for (initialization expression; cyclic conditional expression; post-loop action expression)
{
EXECUTE statement block
}
For example multiplication formulas:

private static void multiplication formula () {
for (int a=1;a<=9;a++) {
for (int b=1;b<=a;b++) {
System.out.print (A + "*" + B + "=" +a*b + "\ t");

}
System.out.println ();


}
}

Loop Interrupt Statement-break, continue
Interrupt statement
Labels can be used in multiple loops to specify the specific loop of interrupts
The break statement is used to terminate execution of a block of statements. Used in the Loop statement body, you can forcibly exit the loop.
"Break;" Statement: can appear in the while, Do...while, for, switch statement body.
Break Label statement: can appear in any body of the statement. The majority is still used in the loop.
The continue statement is used in the Loop statement body to terminate a looping process, skipping a loop that is not executed under the Continue statement in the loop body, and starting the next cycle.
"CONTINUE;" Statement: can only appear in the Loop statement while, Do...while, for









Java Looping statements

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.