Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
嵌套的WHILE循环未按预期运行-Javascript/Google应用程序脚本_Javascript_Google Apps Script_Wolfram Mathematica_Nested Loops - Fatal编程技术网

嵌套的WHILE循环未按预期运行-Javascript/Google应用程序脚本

嵌套的WHILE循环未按预期运行-Javascript/Google应用程序脚本,javascript,google-apps-script,wolfram-mathematica,nested-loops,Javascript,Google Apps Script,Wolfram Mathematica,Nested Loops,我有一个函数没有按预期运行。在我继续之前,我想先介绍一个事实,我通常用Mathematica编程,并负责将Mathematica函数(我编写的)移植到JavaScript,以便可以在Google Docs电子表格中使用。我有大约3小时的JavaScript经验 整个(小型)项目是在给定晶片和晶片尺寸(以及其他输入)的情况下,计算每个晶片的总晶片数。不工作的部分是我检查模具的任何一个角是否超出有效半径Reff的地方 该函数获取一个X和Y坐标列表,组合后,创建模具中心的单个XY坐标。然后将其放入一个

我有一个函数没有按预期运行。在我继续之前,我想先介绍一个事实,我通常用Mathematica编程,并负责将Mathematica函数(我编写的)移植到JavaScript,以便可以在Google Docs电子表格中使用。我有大约3小时的JavaScript经验

整个(小型)项目是在给定晶片和晶片尺寸(以及其他输入)的情况下,计算每个晶片的总晶片数。不工作的部分是我检查模具的任何一个角是否超出有效半径Reff的地方

该函数获取一个X和Y坐标列表,组合后,创建模具中心的单个XY坐标。然后将其放入一个单独的函数“maxDistance”,该函数计算4个角点中每个角点的距离,并返回最大值。该最大值根据Reff进行检查。如果最大值在半径内,则模具计数将增加1

// Take a list of X and Y values and calculate the Gross Die per Wafer
function CoordsToGDW(Reff,xSize,ySize,xCoords,yCoords) {

  // Initialize Variables
  var count = 0;

  // Nested loops create all the x,y coords of the die centers
  for (var i = 0; i < xCoords.length; i++) {
    for (var j = 0; j < yCoords.length, j++) {         
      // Add 1 to the die count if the distance is within the effective radius
      if (maxDistance(xCoords[i],yCoords[j],xSize,ySize) <= Reff) {count = count + 1}
    }
  }

  return count;
}
我知道maxDistance()正在返回正确的值。那么,我的简单错误在哪里

另外,请原谅我用数学符号写了一些东西

编辑#1:稍微格式化一下


编辑#2:根据showi,我已将WHILE循环更改为FOR循环,并替换如果我没有错,则在执行此操作时,您使用的元素比实际数组大小多一个

while(i
while(i

试试这个

,这样我的嵌套循环就可以正常工作了:当我删除maxDistance函数并用1替换它时(因此1.1.Yes,{}是列表(数组)的Mathematica表示法).2.FOR循环确实减少了行数。我编辑了代码以反映这一点3.使小于/小于等于更改。
xArray={-52.25, -42.75, -33.25, -23.75, -14.25, -4.75, 4.75, 14.25, 23.75, 33.25, 42.75, 52.25, 61.75}
yArray={-52.5, -45.5, -38.5, -31.5, -24.5, -17.5, -10.5, -3.5, 3.5, 10.5, 17.5, 24.5, 31.5, 38.5, 45.5, 52.5, 59.5}
CoordsToGDW(45,9.5,7.0,xArray,yArray)
  returns: 49 (should be 72)

xArray={-36, -28, -20, -12, -4, 4, 12, 20, 28, 36, 44}
yArray={-39, -33, -27, -21, -15, -9, -3, 3, 9, 15, 21, 27, 33, 39, 45}
CoordsToGDW(32.5,8,6,xArray,yArray)
  returns: 39 (should be 48)
while (i < xCoords.length) {
    j = 0;
    while (j < yCoords.length) {