Java Control flow

Source: Internet
Author: User

One:

Block scope

Block (i.e. compound statement): Refers to a number of simple Java statements enclosed by a pair of curly braces. The block determines the scope of the variable, and one block can be nested within another block, as follows:

1  Public classprint_in {2      Public Static voidMain (string[] args) {3     inta=2;4         {5             intA=3;6             intB=3;7         }8     }9}

Note: In a block, define a variable, can not be nested in the block in the definition of the same variable, if the definition will error.

Two: if statement

The IF statement in Java is different from the IF statement in Python, Python can be used as an array, string, dictionary and so on to serve as a condition, but in Java can only use the expression directly can judge the Boolean value, can make judgments, otherwise it will error.

1  Public classprint_in {2      Public Static voidMain (string[] args) {3     inta=2;4     intV=4;5     if(a<4){6System.out.println ("OK");7}Else {8System.out.println ("Bad");9     }Ten     } One}

Java Control flow

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.