Java basic programming structure (4)

Source: Internet
Author: User
(8) Control Process
1. Block Scope
Public static void main (string [] ARGs)
{
Int N;
...
{
Int K;
...
} // K is only defined up to here
}

Public static void main (string [] ARGs)
{
Int N;
...
{
Int K;
Int N; // error -- can't redefine N in inner Block
...
}
}

2. conditional statements
If (condition) Statement

3. Loop
Initialization;
While (loopcontinuationcondition ){
Statement;
Increment;
}

4. Determine the cycle
For (initialization; loopcontinuationcondition; increment) statement;

5. Multiple options -- switch statement
I believe you are familiar with it. Here, we need to note that you cannot use string, but you can only use integer.

String input = ...;
Switch (input) // Error
{
Case "A": // Error
...
Break;
...
}

6. interrupt control flow statements
Break;
Jump out to the outside of the control block;

Break label;
You can jump to the tag location, but the tag must be placed before the outermost loop.
Add a colon to the label.

Continue;
Jump out of the control block;

Continue label;
You can jump to the loop that matches the tag.
Add a colon to the label.

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.