Judgment and loop statement Structure

Source: Internet
Author: User

I. Judgment statement:

1. If statement:

A. If (){

// Execute the statement;

}

B. If (){

// Execute the statement;

} Else {

// Execute the statement;

}

C. If (){

// Execute the statement;

} Else if {

// Execute the statement;

}

......

Else {

// Execute the statement;

}

2. Switch statement:

Switch (expression ){

Case constant expression 1: Statement 1;

Case constant expression 2: Statement 2;

......

Default: statement;

}

Ii. Loop statement:

1. For Loop statement:

For (Initial Value of the cyclic variable; cyclic condition; value-added value of the cyclic variable ){

Statement;

}

2. While loop:

While (condition ){

// Loop body;

}

3. Do while loop:

Do {

// Loop body;

} While (condition)

Iii. Differences between loop statements:

1. For and while loops:

For loops are mostly used to know the number of loops;

While loops are mostly used to determine the number of loops without knowing the number of loops;

2. Differences between a while loop and a do while loop:

Do while first executes the loop body, and then judges the condition. If the condition is met, continue the execution. If the condition is not met, exit the loop;

When a while loop first determines the condition, it executes the loop body and does not exit;

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.