Java Programming Idea: The 4th Chapter controls the execution flow

Source: Internet
Author: User

4.1 True and False

All conditional statements are judged by true and false.

4.2 If-else

if (BOOL-EXP) statement; or if (BOOL-EXP) statement; else statement;

4.3 iterations

while (b) {} do{}while (b)

for (init;b;step) {}init You can define multiple initial variables with commas

4.4 foreach Syntax

Enhanced for loop for (T T: Collection/array) {}

4.5 Return

4.6 Break and continue

Any iteration statement body can use break and continue to control the loop flow.

can be used with tags: interrupts the loop until the label is in place.

Note: The only reason to use tags in Java is because there is a loop nesting, and you want to break or continue from multiple nested nesting;

4.7 Infamous Goto

4.8 Switch

Depending on the integer expression, you can choose one from a series of code to execute.

Switch (INT-EXP) {

Case Int-val1:st1; Break

...

DEFAULT:SN;

Integer expressions include byte, short, char, int , and encapsulated classes and enums

Note: Starting with 1.7 string can also be, the principle is to convert a string to hashcode as an int to handle

}

Java Programming Idea: The 4th Chapter controls the execution flow

Related Article

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.