19.8.13js cycle

 

js cycle are:

 

for loop:

for (EXP1; EXP2, EXP3) { 
 loop body; 
} 
EXP1: unconditional execution of the first expression 
exp2: determining whether an execution condition of the loop body 
exp3: increment operations do

By the end of the break for loop

for(var i=1;i<=100;i++){
if(i>100){
break;//结束for循环 
  }
document。write(i+'/<br/>');
}

continue: means skip the current cycle, enter the next cycle.

for( var i=1; i<=10;i++){
if (i==3){
document.write(i+'hello');
continue;
}
document.write(i+'<br/>')
}

for the nested loop

for ( var I =. 1; I <=. 3; I ++ ) { 
document.write ( 'outer loop of the' + i 'results herein <br />' );
 for ( var J =. 1; J <= 2; ++ J ) { 
document.write ( 'inner loop of the' + i 'results herein <br/>' ); 
} 
Document. Write ( '<HR />' ); 
}

Conditional statements:

if the conditional statement

IF (. 3>. 11 ) 
document.write ( 'Hello' ); 
document.write ( 'of hello2' );
 // this wording is correct, when the condition that triggered the first, if not satisfied, the trigger surprised
if ( to false ) { 
document.write ( 'Hello' ) 
document.write ( 'King' )
 var X =. 1, Y = 2, username = 'King' 
} 
// when if there is false, var judged only , x, y, username type rather than judgment value.

 

 
 
<scrip>

var
username = 'King' ; IF (username == 'King' ) { document.write ( 'Hello King' ); } the else { document.write ( 'Hello Nana' ); }
// when the operation time, outputs '
Hello Nana', since the inside js, represents a length of a space point,
so the 'king' and 'king' is not the same.
</scrip>

 

switch ... case statement

  • Calculated once the switch expression
  • The value of the expression is compared with the value for each case of
  • If there is a match, then the association code execution
<Scrip> 
Switch (exp) { Case Value 1: code segments executed; BREAK ; Case Value 2: code segments executed; BREAK ; ... default : code segments executed; BREAK ; more stringent type }
</scrip>
 

 while loop: Calcd expression, when the value is true (non-zero), the loop statement is executed.

the while (loop condition) { 
cycle theme; 
}

 

do ... while loop: The difference and while do-while loop is that: it is the first execution of the loop statement, and then determine whether the expression is true, if the loop continues is true; if false, is terminated cycle. Therefore, do-while loop to execute at least one loop.

JavaScript conditional statement

if statement: If the condition is true for a predetermined sj is a block of code to be executed

else statement: The original provision was added condition is false the new conditions

else if statement: originally specified when the new condition is flase first condition

The switch statement: perform different actions for different conditions

 

Guess you like

Origin www.cnblogs.com/zxli/p/11348527.html