JavaScript The process control of is divided into sequential structure , Branch structure and loop structure

This chapter mainly explains the branch structure

one ,if sentence

1.if Single branch statement

The syntax is as follows :

  Condition establishment execution code , Or do nothing

if ( Conditional expression ) {
      Code statement executed when the condition is satisfied

if The execution thought of single branch statement :

Implementation ideas : If if The result of the conditional expression inside is true true, Then the   Execute statement
If if Condition expression result is false , Do not execute the statements in braces , implement if Code after statement

  two ,if   else   Double branch statement  

The syntax is as follows :

  Implementation of conditions if The statement inside , Otherwise execute else The statement inside

if( Conditional expression ){
        Execute statement 1
        Execute statement 2

 if Thoughts on the execution of double branch statements :

  Implementation ideas : If the expression results in true ,   Then execute the statement 1, Otherwise execute the statement 2 
    else   Immediately followed by an enlarged bracket

three ,if   else  Multi branch statement  

The syntax is as follows :

if ( Conditional expression 1){
      sentence 1;
}else  if( Conditional expression 2){
      sentence 2;
}else  if( Conditional expression 3){
      sentence 3;
      None of the above holds for the last statement

 if The thought of executing multi branch statements :

If the conditional expression 1 Execute when satisfied sentence 1, After execution , Exit entire if Branch statement
If the conditional expression 1 dissatisfaction , Then judge the conditional expression 2 , If satisfied , Execute statement 2, and so on

If none of the above conditional expressions holds , Then execute else The statement inside

1. Multi branch statement or multi selection 1, Only one statement can be executed at last
                              else  if Theoretically, there can be any number of conditions

  four , Ternary operator

The syntax is as follows :

Conditional expression  ?   expression 1   :   expression 2

Implementation of ternary operators :

Implementation ideas : If the conditional expression results in true , Returns the expression 1 Value of , If the conditional expression result is false ,                        Returns the expression 2 Value of  

Expression has a return value , To assign a value to a variable

five , switch sentence  

The syntax is as follows :

switch( expression ){
       case   value1:
                  Execute statement 1( be equal to value1) Code to execute when ;
         case   value2:
                  Execute statement 2;
                  Execute the last statement ;

switch Execution idea of statement :

Using the value of our expression and case The following option values match , If match on , Execute the case The statement inside , If none of them match , Then execute default The statement inside

  Multi branch statement , Multiple selections can be realized 1

Used to execute different code based on different conditions , When you want to set a series of     Specific value     Options for , Can be used switch

 switch matters needing attention :

1.switch Later expressions are often written as variables , You have to declare a variable first

2. Value of expression and case When the values inside match   Congruence  , The value and data type must be consistent

3.break   If the current case Not in it break  , Will not exit switch, Yes proceed to next case

©2019-2020 Toolsou All rights reserved,
Solve in servlet The Chinese output in is a question mark C String function and character function in language MySQL management 35 A small coup optimization Java performance —— Concise article Seven sorting algorithms (java code ) use Ansible Batch deployment SSH Password free login to remote host according to excel generate create Build table SQL sentence Spring Source code series ( sixteen )Spring merge BeanDefinition Principle of Virtual machine installation Linux course What are the common exception classes ?