本文介绍了For循环重复第一个循环两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个for循环,它似乎在重复第一个循环两次(x = 0),然后不做最后一个循环(x = 2)

I have this for loop, and it seems to be repeating the first loop twice (x=0) and then not doing the last one (x=2)

for (x=0;x<=2;x++)
    {
        if (document.getElementById("sub"+catCount+x).value != "")
        {
            if (nonums.test(document.getElementById("sub"+catCount+x).value))
            {
                total = total + parseFloat(document.getElementById("sub"+catCount+x).value);
            }
        }
        alert(x);
    }

换句话说,我得到两个带有"0"的警报框,然后是其中带有"1"的警报框.

In other words, I get two alert boxes with "0" in them, then one with "1" in it, and that's it.

有人可以告诉我我在这里没看到什么吗?为什么它不正常地循环遍历(0,1,2)?

Can anyone tell me what I'm not seeing here? Why doesn't it just progress through the loop normally (0,1,2)?

推荐答案

它对我有用.

for (x=0;x<=2;x++)
{
  alert(x);
}

您可以在控制台上对其进行测试.

You can test it at console.

这篇关于For循环重复第一个循环两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-19 01:05
查看更多