Java language Syntax-control structure

Source: Internet
Author: User
Tags continue expression
Control | Grammar control structure
As in other languages, Java also contains the following three control structures:
A sequential structure
Statements are executed one after another in the order in which they were written.

Two-choice structure
1 IF Select structure:
if (logical value)
{
Statement
}
2 If/else choose to dismiss:
if (logical value)
{
Statement
}
Else
{
Statement
}
3 Switch structure:
switch{expression}
{
Case value1:
Statement
Break
Case value2:
Statement
Break
...
...
Default
Statement
}

Three-cycle structure
1 while follow the bad structure:
while (logical value)
{
Statement
}
2 do/while to follow the bad structure:
Todo
{
Statement
}
while (logical value)
3 for structure:
for (expression 1; expression 2; expression 3)
{
Statement
}
General usage:
for (int i=0 i < i++)
{
Statement
}

There are also three important key word return, break and continue in the process:
Return: Ends the method and returns directly.
Break: Used in loops to jump out of the loop (end loop) and enter the next statement after the structure. Jump out of the switch structure in the switch.
Continue: Used to jump out of this cycle, into the next cycle.

Break and continue can also be used in conjunction with tags, but their use of labels is limited, not as unscrupulous as the previous goto statements. Break and continue use tags to improve the flexibility of the 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.