Blogger Information
Blog 9
fans 0
comment 0
visits 6596
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
3.26 循环:for;while;do while
师太的小迷弟的博客
Original
933 people have browsed it

总结:

for(初始值;条件;步数){

//三个值缺一不可,

循环代码;

}

var a=2;//初始值

while(条件){

    循环代码;

    a++;//步数

    while先判断再循环

}

do{

    循环代码

    a++;

}while(条件)


实例

for九九乘法表

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
  <script type="text/javascript">
   
    for(i=1;i<10;i++){
      for(j=i;j<10;j++){
        var kong="     "
        if(j*i>=10){//如果j乘以i大于10
          kong="   "
        }
        document.write(i+'X'+j+'='+(j*i)+kong)
      }
      document.write('<br>')
    }
 
  </script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

while乘法表

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
  <script type="text/javascript">
    var q=1;
    while(q<10){
      var w=q;
      while(w<10){
        var kong="     "
        if(q*w>=10){kong="   "}
        document.write(q+'X'+w+'='+(q*w)+kong);
        w++;
      }
      document.write('<br>')
      q++
    }


  </script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

*三角

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
  <script type="text/javascript">
    var e=20;
    while(e>0){
      var r=e;
      while(r>0){
        document.write('*');
        r--;
      }
      document.write('<br>')
      e--;
    }
  </script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

 

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post