问答详情
源自:4-9 继续循环continue

用while为什么不行

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>continue</title>

<script type="text/JavaScript">

 var mynum =new Array(70,80,66,90,50,100,89);//定义数组mynum并赋值

 var i=0;

 while(i<mynum.length)

 {

  if(mynum[i]<60)

    {

continue;


}

document.write("成绩:"+mynum[i]+"及格,输出!"+"<br>");

i++;

}

</script>

</head>

<body>

</body>

</html>


提问者:dreamer2015 2015-03-01 13:40

个回答

  • lymo
    2015-03-01 16:12:36
    已采纳

    if(mynum[i]<60)这里遇到小于60的话,因为i没自增,会死循环。。。

  • Werk_Bicth
    2016-06-20 19:38:32

     var arr=[80,96,75,50,60,100,92,50,62];
    var i=-1;
    while(i<arr.length-1)
    {
    i++;
    if(arr[i]<70)
    {
    document.write("成绩不好,不输出。"+"<br>");
    continue;
    }
    else{
    document.write("成绩是:"+arr[i]+"<br>");
    }
    
    }


  • 鲜衣
    2015-09-06 12:37:34

    <script type="text/JavaScript">
     var mynum =new Array(70,80,66,90,50,100,89);//定义数组mynum并赋值
     var i=0;
     while(i<mynum.length)
     {
      	if(mynum[i]<60)
        {
    	document.write("成绩不及格,不输出!"+"<br>");
    i++;
    continue;
    	}
    	document.write("成绩:"+mynum[i]+"及格,输出!"+"<br>");
        i++;
    }
    </script>