Java Programming thought Fourth chapter

Source: Internet
Author: User

Fourth Chapter

Directory:

    • 4.1 True and False
    • 4.2 If-else
    • 4.3 iterations
    • 4.4 foreach Syntax
    • 4.5 return
    • 4.6 Break and continue
    • 4.7 Goto
    • 4.8 Switch
4.1 True and False

Note that Java does not allow us to use a number as a Boolean value, which differs from C and C + + (true is nonzero in C + +, and false is 0). If you use a number as a Boolean expression, the Java compiler will directly error .

4.3.1 Do-while And while

The difference is that Do-while is executed at least once, while the code within the loop structure is not executed as long as false

4.3.2 For Loop

for (int i;;) The I variable is defined when the program uses it, that is, when it is defined in the for time, not in main (), and I is only in for, and C is different, C requires that all variables are defined at the beginning of a block so that the compiler can create the block.

Allocate space

4.3.3 Comma delimiter

For loops, you can define multiple variables with a comma operator, but each variable must have the same type, such as: for (int i=1,j=i+10; i<5; i++,i=i*2), and this method can only be used in for, other selection or iteration statements do not apply

4.4 For each syntax

Indicates that you do not have to create an int variable to count the sequence of access items, and foreach automatically generates

for (char c: "I love my Babychun". ToCharArray ()) System.out.println (c);

String can use the ToCharArray () method to return a char array

4.5 return

Return keyword two purposes: 1. Specifies what value a method returns, 2. This method may cause the exit to be exited and return a value, and an implicit return in the Void method

4.6 Break,continue

Break interrupts the iteration and then the iteration is no longer executed, continue interrupts the iteration and begins the next iteration

4.8 Switch

Break in Switch-case can be omitted, and if omitted, the subsequent statement continues until the next break is encountered

Java Programming thought Fourth chapter

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.