Java Chapter Fourth

Source: Internet
Author: User

      Fourth chapter selection Structure (ii) What is the execution flow of the switch selection structure?      Switch Select the function of the break keyword in the structure?     This chapter aims to master the switch selection structure to solve the problem by using the If selection structure and switch selection structure. Why use the switch selection structure with multiple if selection structure--Cons: Complex structure, verbose use switch selection structure solution--Characteristics: The condition is equivalent to judge what is S                                 Witch Select structure Switch Select structure switch (expression) {//integer or character case//constant 1: Evaluates the value of an expression    statement; break;//if equals constant 1 case           Constant 2://If equal to constant 2 statement; Default://If no matching value statement is found; break} Note: If you need to jump out after each case, do not forget to write Brea                               K.               The constants following the case must be different, and the default block order can change, but be aware of the order in which they are executed.                           Usually, the default block is placed at the end, or it can be omitted. The value of the expression in the parentheses behind the switch must be an integer or a character-type comparison switch And the multiple if selection structure is the same point: all are used to deal with multi-branch conditions of the structure of different points: Switch selection structure can only handle the condition of the equivalence, and the condition must be an integer variable or the character variable multiple if selection structure does not have the restriction of switch selection structure, especially for the case where a variable is in a continuous interval. Select Structure Summary:
If selection structure

Basic if selection structure: situations where single or combined conditions are handled
IF-ELSE selection structure: Handling simple conditional branching situations
Multiple if selection structure: dealing with complex conditional branching situations
Nested IF selection structure: For more complex process Control
Switch selection structure
Multiple branches and condition judgment is the case of equivalence judgment.

Summarize:
Switch selection structure is applicable to condition judgment is the case of equivalence judgment
In practical applications, it is common to use multiple forms to select structural synthesis to solve more complex problems!

Java Chapter Fourth

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.