For循环重复第一个循环两次 [英] For Loop repeats first loop twice

查看:456
本文介绍了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)?

推荐答案

这实际上是我使用的唯一位置 任何页面上的变量x.

that is literally the only spot I use the variable x on any page.

它对我有用.

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

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

You can test it at console.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆