First, Process Control Overview
Process Control of the program
-Program = data + algorithm
-Any complex program algorithm can be implemented by "order", "branch", "Loop" three basic program logic combinations
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7E/03/wKioL1b1AUfw0hZ9AACpC1gtV4A054.png "title=" Web.png "alt=" Wkiol1b1aufw0hz9aacpc1gtv4a054.png "/>
Overview of branching structures
-The program can execute certain statements selectively in different situations during the running process
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7E/03/wKioL1b1AkGT07dIAAEgU8byRXo291.png "title=" Web.png "alt=" Wkiol1b1akgt07diaaegu8byrxo291.png "/>
Second, if statement
Execution logic for an if statement
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7E/06/wKiom1b1Akvyb0bqAAGBqU8o8FY316.png "title=" Web.png "alt=" Wkiom1b1akvyb0bqaagbqu8o8fy316.png "/>
If statement flowchart
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7E/03/wKioL1b1A3mA0uvRAAEqrhzKZKM104.png "title=" Web.png "alt=" Wkiol1b1a3ma0uvraaeqrhzkzkm104.png "/>
-A Boolean value is required by default in the IF decision
-If the value that appears is not a Boolean type, it is automatically converted
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7E/03/wKioL1b1BgXwe_AWAADAjP4urWE007.png "title=" Web.png "alt=" Wkiol1b1bgxwe_awaadajp4urwe007.png "/>
If statement block do not omit ' {} '
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7E/06/wKiom1b1BaqhSV2qAAHiwxkzj6Y084.png "title=" Web.png "alt=" Wkiom1b1baqhsv2qaahiwxkzj6y084.png "/>
Third, If-else statement
Execution logic for IF-ELSE statements
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7E/03/wKioL1b1CFmQAcOCAAGLXFrBcXs727.png "title=" Web.png "alt=" Wkiol1b1cfmqacocaaglxfrbcxs727.png "/>
Iv. else If statement
If-else Statement Nesting
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7E/03/wKioL1b1B2-C3wVoAAEV60J4XLM261.png "title=" Web.png "alt=" Wkiol1b1b2-c3wvoaaev60j4xlm261.png "/>
Else if statement execution logic
-in fact, the else if structure is a simple way to do if else nesting
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7E/03/wKioL1b1B7eimGwcAAEE4b4XUHk631.png "title=" Web.png "alt=" Wkiol1b1b7eimgwcaaee4b4xuhk631.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7E/07/wKiom1b1B0SjBK8gAAF0fljaWfU989.png "title=" Web.png "alt=" Wkiom1b1b0sjbk8gaaf0fljawfu989.png "/>
V. Switch-case statements
Switch-case Statement Execution logic
-The Switch-case statement is a special per-point structure that can be executed from different program entrances depending on the value of an expression
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7E/03/wKioL1b1CqCjaqsXAACCUusN7T4447.png "title=" Web.png "alt=" Wkiol1b1cqcjaqsxaaccuusn7t4447.png "/>
Switch-case and break joint use
-Usually the case1, Case2 、...、 CaseN correspond to a completely different operation and can be used in conjunction with the break statement, exit the switch block after executing the complete statement, do not proceed with the following statement,
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7E/07/wKiom1b1CvTQFzu0AABqd1FMpbM077.png "title=" Web.png "alt=" Wkiom1b1cvtqfzu0aabqd1fmpbm077.png "/>
Switch-case Statements for branching
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7E/07/wKiom1b1C3nCTAYyAABg1QJ0kqA019.png "title=" Web.png "alt=" Wkiom1b1c3nctayyaabg1qj0kqa019.png "/>
Advantages of Switch-case
-Switch-case is often used in conjunction with break statements to implement branching functions
-The main difference between Switch-case and if-else when implementing branching functions is that
-Switch...case ... The structure is clearer and more efficient, but it is generally used only to specify that a variable is equal to a specific value within a range
Summary: This chapter covers the basics of JavaScript -6 JavaScript branching structure (if, if-else, else if, switch-case)
This article from the "Technical Exchange" blog, declined reprint!
JavaScript base -6 JavaScript branching structure (if, if-else, else if, switch-case)