问题标签 [for-in-loop]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
5703 浏览

javascript - 在 for...in 循环中重置迭代器

这是我用来绘制一些随机圆圈的代码的一部分:

问题是,当存在重叠时,不会检查具有新生成坐标的圆是否与已经检查过重叠圆的圆重叠。在使用 continue 语句之前,我尝试将 i 设置为 0,但这不起作用。请帮忙,我真的很困惑。

0 投票
5 回答
120061 浏览

python - Python for-in 循环前面有一个变量

在谷歌搜索和搜索后,无法弄清楚这是做什么的。也许我没有寻找正确的东西,但它就在这里。非常感谢揭穿这种速记的任何输入。

0 投票
3 回答
189 浏览

javascript - Javascript:为什么对数组使用 for 循环而不是 for-in 循环?

我一直在阅读 Stoyan Stefanov 的面向对象的 Javascript,有一次他写道:

for-in循环用于迭代数组(或对象,我们将在后面看到)的元素。这是它的唯一用途;它不能用作替代foror的通用重复机制while。让我们看一个使用 afor-in循环遍历数组元素的示例。但请记住,这仅用于提供信息,因为for-in它主要适用于对象,并且for应将常规循环用于数组。

for我过去在迭代数组元素时一直使用循环,我通常看到for循环不是for-in用于此目的的循环,但是“常规for循环应该用于数组”的原因是什么?

0 投票
1 回答
185 浏览

unix - 如何在 for...in 循环中使用 unix 上的 shell 脚本替换文件路径的一部分?

非常需要帮助。我完全坚持这个。我正在(递归地)遍历目录中的所有文件并打印文件列表。就像是:

打印列表时,我想将文件的路径从 srcDir 替换为 tgtDir。就像是:

我希望你明白了。请指教。

0 投票
5 回答
561 浏览

delphi - 使用“for in”语句和编译器错误 E2064

我想在 D2010 下的测试用例中使用for in sentence。

如果我想写入Param.Value变量,那么编译器会报告错误 2064,但允许从同一记录写入Param.Edit.text ,为什么?

测试用例:

0 投票
5 回答
3127 浏览

javascript - For .. 在循环中?

我在这里失去了它。我现在对这个循环是如何工作的感到非常困惑。

来自 w3 学校:

人是具有属性的对象吗?如何使用方括号访问这些属性?我以为那是为了数组?

为什么这也有效,不应该只是这样吗?:

0 投票
1 回答
850 浏览

r - for循环中的for循环?

我有两个数据框:

通过使用两个数据框,我想计算 zscore。功能是:

df1 包含所有 X 值,df2 数据框的每一行都包含用于计算平均值和 sd 的值。我生成一个循环,为 df1 第一列中的每个值计算 z 分数。但现在我的问题是:如何计算整个数据帧的 z 分数?

谢谢你们!

0 投票
1 回答
143 浏览

list - for-in-loop/ Condition 仅用于 a List 的第一个元素

找了三天没找到解决办法,代码如下:

每个块位置等于我可以通过单击屏幕创建的块,然后将新块位置放入列表中。基本上,我的 BlockPosition 列表中有一个块坐标列表。然后我传递每个块位置的条件,条件为每个块位置创建一个矩形,为玩家创建一个矩形......如果发生碰撞,玩家将不会朝那个方向移动。当我尝试代码时,我的角色只会与列表的第一个元素而不是其他元素发生碰撞,如果我删除第一个元素,它将与下一个元素发生碰撞,但不会与其他元素发生碰撞。所有变量都很好我知道,因为我试图用这样的东西替换这段代码:

同样的事情,但是如果它发生碰撞,我会删除列表的元素,这是相同的条件,但是当我尝试它时,它会检测到所有元素并删除我触摸的元素。我尝试了 foreach 函数,得到了相同的结果。怎么了?我已经用 dos 变量做了很多事情所以我确信问题不是来自它们的值,而是来自我对它们所做的事情。请帮忙!(:

0 投票
3 回答
145 浏览

c# - for-in-loop/ Condition Is only used for the first element of the a List

I have searched for three days and didn't find a solution, Here is the code:

Each Block position equals a block that I can create by clicking on the screen, the new block position is then put in the List. Basically I have a list of blocks Coordinates in my BlockPosition List. Then I pass the condition for each blockposition, the Condition Create A rectangle for each BlockPosition and one for the Player... if there's a collision, the player won't move in that direction. When I try the code, My character will Collide only with the first element of the List and not the others, if I delete the first element it will then collide with the next one but not the others. All the variables are FINE I know it because I tried to replace this code by something like this:

Same thing but here if it collides I delete the Element of the List, it's the same condition but when I try it it will detect all of the elements and delete the ones that I touch. I tried the foreach function and I get the same Results. What's wrong? I already do a lot of things with does variables So I'm sure the problem don't come from their values but with what I do with them. Help please! (:

0 投票
0 回答
74 浏览

c# - 了解 for-in-loop 计算

我这里有这个小代码,像素从顶部掉落,如果它们与块碰撞,它们将停留在块的表面上。然后,如果有另一个像素落在不再下降的像素上,它将加起来。嗯,这就是我想要做的,但是在第二个像素加起来之后,就没有更多的像素会超过其他像素。我虽然 j-1 是索引中的当前 int (- 1) 所以如果它是 10,那么它将是 9,所以我有点困惑为什么 (int)Position[j - 1].Y - 1 没有不能正常工作。

如果我放了很多块,我也会遇到一些滞后问题,有没有办法优化这个?