Google apps script 对于循环迭代,在某个数字处停止

Google apps script 对于循环迭代,在某个数字处停止,google-apps-script,Google Apps Script,我有41个对象数组,我有一个循环代码来执行检查,我有一个IF循环,如果检查超出范围,它将触发一封电子邮件。我的params通过0-57,因为我有58个参数,但我只需要其中的41个 当myparamInfo.length为41 var params = new Array(); var lowerlimit = Number.NEGATIVE_INFINITY; for(var i = 0; i<58; i++){ params[i] = e.values[i]; }

我有
41个对象数组
,我有一个
循环代码来执行检查,我有一个IF循环,如果检查超出范围,它将触发一封电子邮件。我的
params
通过
0-57
,因为我有
58个参数
,但我只需要其中的
41个

当my
paramInfo.length
41

var params = new Array();
  var lowerlimit = Number.NEGATIVE_INFINITY;

  for(var i = 0; i<58; i++){
    params[i] = e.values[i];
  }

  var paraminfo = [
    {
      name: "activechilledsetpt", number: 1, min: activechilledsetptLL, max: activechilledsetptUL
    },
    {
      name: "evapleavingtemp", number: 2, min: evapleavingtempLL, max: evapleavingtempUL
    },
    {
      name: "evapenteringtemp", number: 3, min: evapenteringtempLL, max: evapenteringtempUL
    },
    {
      name: "condenteringtemp", number: 4, min: lowerlimit, max: condenteringtempUL
    },
    {
      name: "condleavingtemp", number: 5, min: condleavingtempLL, max: condleavingtempUL
    },
    {
      name: "activecurrentsetpt", number: 6, min: activecurrentsetptLL, max: activecurrentsetptUL
    },
    {
      name: "rla", number: 7, min: rlaLL, max: rlaUL
    },
    {
      name: "evaprfgtpressckt1", number: 8, min: evaprfgtpressLL, max: evaprfgtpressUL
    },
    {
      name: "condrfgtpressckt1", number: 9, min: condrfgtpressLL, max: condrfgtpressUL
    },
    {
      name: "satcondtempckt1", number: 10, min: satcondtempLL, max: satcondtempUL
    },
    {
      name: "satevaprfgttempckt1", number: 11, min: satevaprfgttempLL, max: satevaprfgttempUL
    },
    {
      name: "purgesuctiontempckt1", number: 13, min: purgesuctiontempLL, max: purgesuctiontempUL
    },
    {
      name: "purgeliquidtempckt1", number: 14, min: purgeliquidtempLL, max: purgeliquidtempUL
    },
    {
      name: "oildiffpressckt1", number: 24, min: diffoilpressLL, max: diffoilpressUL
    },
    {
      name: "oiltanktempckt1", number: 25, min: oiltanktempLL, max: oiltanktempUL
    },
    {
      name: "dischoilpressckt1", number: 26, min: dischoilpressLL, max: dischoilpressUL
    },
    {
      name: "oiltankpressckt1", number: 27, min: oiltankpressLL, max: oiltankpressUL
    },
    {
      name: "comphaseAckt1", number: 28, min: comphaseampLL, max: comphaseampUL
    },
    {
      name: "comphaseBckt1", number: 29, min: comphaseampLL, max: comphaseampUL
    },
    {
      name: "comphaseCckt1", number: 30, min: comphaseampLL, max: comphaseampUL
    },
    {
      name: "voltageckt1", number: 31, min: voltageLL, max: voltageUL
    },
    {
      name: "comwindingtempW1ckt1", number: 32, min: comwindingtempLL, max: comwindingtempUL
    },
    {
      name: "comwindingtempW2ckt1", number: 33, min: comwindingtempLL, max: comwindingtempUL
    },
    {
      name: "comwindingtempW3ckt1", number: 34, min: comwindingtempLL, max: comwindingtempUL
    },
    {
      name: "evaprfgtpressckt2", number: 16, min: evaprfgtpressLL, max: evaprfgtpressUL
    },
    {
      name: "condrfgtpressckt2", number: 17, min: condrfgtpressLL, max: condrfgtpressUL
    },
    {
      name: "satcondtempckt2", number: 18, min: satcondtempLL, max: satcondtempUL
    },
    {
      name: "satevaprfgttempckt2", number: 19, min: satevaprfgttempLL, max: satevaprfgttempUL
    },
    {
      name: "purgesuctiontempckt2", number: 21, min: purgesuctiontempLL, max: purgesuctiontempUL
    },
    {
      name: "purgeliquidtempckt2", number: 22, min: purgeliquidtempLL, max: purgeliquidtempUL
    },
    {
      name: "oildiffpressckt2", number: 40, min: diffoilpressLL, max: diffoilpressUL
    },
    {
      name: "oiltanktempckt2", number: 41, min: oiltanktempLL, max: oiltanktempUL
    },
    {
      name: "dischoilpressckt2", number: 42, min: dischoilpressLL, max: dischoilpressUL
    },
    {
      name: "oiltankpress", number: 43, min: oiltankpressLL, max: oiltankpressUL
    },
    {
      name: "comphaseAckt2", number: 44, min: comphaseampLL, max: comphaseampUL
    },
    {
      name: "comphaseBckt2", number: 45, min: comphaseampLL, max: comphaseampUL
    },
    {
      name: "comphaseCckt2", number: 46, min: comphaseampLL, max: comphaseampUL
    },
    {
      name: "voltageckt2", number: 47, min: voltageLL, max: voltageUL
    },
    {
      name: "comwindingtempW1ckt2", number: 48, min: comwindingtempLL, max: comwindingtempUL
    },
    {
      name: "comwindingtempW2ckt2", number: 49, min: comwindingtempLL, max: comwindingtempUL
    },
    {
      name: "comwindingtempW3ckt2", number: 50, min: comwindingtempLL, max: comwindingtempUL
    }];

  console.log("ParamINFO LEGNTH: "+paraminfo.length)

  for(var z = 0; z < paraminfo.length; z++){
   var paraminfoCheck = paraminfo[z];
    console.log("Z Value: "+z);
   var template = HtmlService.createTemplateFromFile(paraminfoCheck.name);
   template[paraminfoCheck.name] = params[paraminfoCheck.number];
   template.recorded = params[56];
   template.remarks = params[57];

    if((params[paraminfoCheck.number] <= paraminfoCheck.min)|| (params[paraminfoCheck.number] >= paraminfoCheck.max)){
     // Logger.log("Number: "+params[paraminfoCheck.number]+"Name: "+paraminfoCheck.name+"Value: "+paraminfoCheck)
    MailApp.sendEmail("someone@gmail.com",
    "Parameter Out of Range Notification",
     "",{htmlBody: template.evaluate().getContent()});

    }else
    {
      return;
    }
var params=new Array();
var lowerlimit=Number.NEGATIVE_无穷大;
对于(var i=0;i

上面的部分给出了问题,现在它工作了。

return
的意思是“停止当前函数的执行”,而不是“退出最内部的作用域”。要退出
for
循环,使用
break
,跳过(剩余的)迭代,使用
continue
明白了。注意到了。谢谢!
}else
{
return;
}