美文网首页
二、JavaScript 声明的标识符

二、JavaScript 声明的标识符

作者: MC_DEV_JIN | 来源:发表于2016-05-23 11:55 被阅读16次

EG:break

var text =""

var i;

for(i =0; i <5; i++) {

if(i ===3) {

break;

}

text +="The number is "+ i +"";

}

Run...

The number is 0

The number is 1

The number is 2

 EG: Label Break;

function myFunction() {    

       var text = "";    var i, j;    Loop1:               // The first for loop is labeled "Loop1"  

       for (i = 0; i < 3; i++) {    

                     text += "" + "i = " + i + ", j = ";          

                     Loop2:           // The second for loop is labeled "Loop2"      

                      for (j = 10; j < 15; j++) {            

                                   if (j === 12) {                

                                            break Loop2;            

                                    }            

                             document.getElementById("demo").innerHTML = text += j + " ";      

                      }  

         }

}

running...

Label Break.html

EG: While

function myFunction() {   

 var text = "";    

  var i = 0;    

     while (i < 10) {     

        text += "The number is " + i;       

         i++;   

      }    

     document.getElementById("demo").innerHTML = text;

}

whiletest.html

EG:do{}while()

function myFunction() {    

        var text = "" ;

         var i = 0;   

          do {        

         text += "The number is " + i;        

          i++;    

          }    while (i < 10)    

         document.getElementById("demo").innerHTML = text;

}

running...

dowhile.html

do {

code block to be executed

}

while (condition);

相关文章

网友评论

      本文标题:二、JavaScript 声明的标识符

      本文链接:https://www.haomeiwen.com/subject/ipsarttx.html