JS circulating and Analyzing

Judgment cycle

Said last note ternary operator, it is determined if the statement corresponds to a simple (if ... else).
1、 if…else

  • Form: if (condition) {block of statements 1} the else {statement block 2}, the order: first determination condition is satisfied, if the established code statement block 1 is performed; if not set up, the code within a block of statement 2 is executed . When there are a plurality of nested conditional statement if, at this time do not build the ternary operator.
  • Further, it has the form of a plurality of juxtaposed judgment statement: if () {} ... else if () {} ... else if () {} else {}, i.e., there may be a plurality of intermediate and else if the if else.
  • determining if, among the determination conditions generally used for a plurality of juxtaposed. For example, in the placement test scores, you can use this conditional.

2、 switch判断语句

  • Form: switch (variable / value) {statement block}, switch determines the statement to if different, it is judged if may range judging, also may be determined by the judgment value; the switch belonging to determine the specific value, but its efficiency than if the determination.

  • In the switch statement block, there are two keywords: break and default. Respectively, out of the current loop is intended, the execution code block is not satisfied case. Default is easy to understand, the key is to break the jump, there are two situations: it can jump out of the current cycle, it can also jump to the designated cycle. Note, break only for the cycle and switch useful for the rest of the (judge sentences) does not work

  • break:

     默认跳转break,跳出当前循环,只需要一个break即可。
    
//break跳转位置,默认跳出当前循环,注意是循环
    for(var i=0;i<20;i++){
        // break将会跳到此位置=================
        for(var j=0;j<10;j++){
            if(i>10){
            console.log(i);
            break;
            }
        } 
    }
	 跳转指定位置,此时需要在目标循环体前,添加一个标志词(随意取),如下:
 // break跳转至指定位置
    flag1:
    for(var i=0;i<100;i++){
	    flag2:
	    for(var j=0;j<10;j++){
	        if(i>50){
	        console.log(i);// ==============51
	        break flag1;
	        }
	    } 
    }

3, loop

在计算机中有三大流程控制语句:顺序控制语句、分支控制语句和循环控制语句。而在循环控制语句中,有while、do-while、while-do、for、for-in、for-each,这将会根据我们的需要,来选择不同的循环方法。这种循环,重点在于循环的把控,有时我们需要清楚每一道循环的结果,而有时我们不需要清楚每一道结果,只要能够得到我们所需要的结果即可。

Released nine original articles · won praise 1 · views 60

Guess you like

Origin blog.csdn.net/qq_42420490/article/details/104828241