Conditional statements, loops, arrays

Source: Internet
Author: User

First, conditional statements

If statement

if (condition 1) {

Code 1

}

else if (condition 2) {

Code 2

}

......

else{

Code n

}

Switch statement

Not commonly used, only the following types of comparisons are supported: String, Char, Boolean, enum, integer

Second, the circular statement

While structure

while (loop condition) {

Loop body

}

Loop control statement:break: End the entire loop immediately

       continue: Immediately ends the current number of loops and runs the next loop

Do.. While structure

do{Loop Body}

while (cyclic condition);

For structure

for (expression 1; loop condition; expression 2) {

Loop body

}

Three, array

Arrays: Used to hold multiple data of the same type

After an array is created, each entry must have a value, and if no assignment is made, the default value is used.

Number type: Default value is 0

String: Default value is null

Boolean type: Default value is False

Char type: The default value is

Array traversal: Gets the data for an item in the array, typically using a for loop, which overrides all subscripts of the array

foreach loop: can only be used to iterate over an array or collection, only in sequential traversal, with fast traversal speed

Iv. Functions (function)

Functions must be declared before they are used:

Modifier return type function name (formal parameter list) {function Body}

Formal parameter list: data type parameter name

Function call: Function name (argument list);

Parameters: Arguments used when declaring a function

Arguments: Parameters used when a function is called

When a function is called, the value of the argument is passed to the parameter.

    

Conditional statements, loops, arrays

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.