title: Improving the conditions needed before sending an email from Google Sheets
body: <p>I came up with some code to send email when column AJ is true. Initially it worked perfectly, but after I add in more guards, it only sends email to the first row.</p>
  
  <p>What i want to achieve: </p>
  
  <ol>
  <li>People will send request and details will be shown in "Form responses 4",</li>
  <li>I would approve, it by indicating <code>TRUE</code> in the last column.</li>
  <li>I click a button to run the script</li>
  <li>Rows with <code>TRUE</code> have data emailed to the email address associated with the row</li>
  </ol>
  
  <p>The code doesn't fully work: if there are three people who should get emailed, only the first will get an email. How can I modify my guards to email everyone whose row has <code>TRUE</code>?</p>
  
  <hr>
  
  <pre><code>function testing(){
    var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
    var lr = ss.getLastRow();
    var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form 
  Responses 4");
  
    for (var i = 2 ; i &lt;= lr ; i++){
      var dpt = targetSheet.getRange(i,4).getValue();
      var purpose = targetSheet.getRange(i,5).getValue();
      var p = "HR", d = "DMS", r = "RIM";
      var check = targetSheet.getRange(i, 36).getValue();
      var currentEmail = targetSheet.getRange(i, 2).getValue();
      var currentName = targetSheet.getRange(i, 3).getValue();
      var remark = targetSheet.getRange(i, 35).getValue();
      var qty1 = targetSheet.getRange(i, 7).getValue();
      var qty2 = targetSheet.getRange(i, 10).getValue();
      var qty3 = targetSheet.getRange(i, 14).getValue();
      var qty4 = targetSheet.getRange(i, 17).getValue();
      var qty5 = targetSheet.getRange(i, 21).getValue();
      var qty6 = targetSheet.getRange(i, 24).getValue();
      var qty7 = targetSheet.getRange(i, 26).getValue();
      var qty8 = targetSheet.getRange(i, 28).getValue();
      var qty9 = targetSheet.getRange(i, 30).getValue();
      var qty10 = targetSheet.getRange(i, 32).getValue();
  
      var ap1 = targetSheet.getRange(i, 8).getValue();
      var ap2 = targetSheet.getRange(i, 11).getValue();
      var ap3 = targetSheet.getRange(i, 15).getValue();
      var ap4 = targetSheet.getRange(i, 18).getValue();
      var ap5 = targetSheet.getRange(i, 22).getValue();
      var ap6 = targetSheet.getRange(i, 25).getValue();
      var ap7 = targetSheet.getRange(i, 27).getValue();
      var ap8 = targetSheet.getRange(i, 29).getValue();
      var ap9 = targetSheet.getRange(i, 31).getValue();
      var ap10 = targetSheet.getRange(i, 33).getValue();
  
      var S1 = targetSheet.getRange(i, 6).getValue();
      var P1 = targetSheet.getRange(i, 9).getValue();
      var S2 = targetSheet.getRange(i, 13).getValue();
      var P2 = targetSheet.getRange(i, 16).getValue();
      var B = targetSheet.getRange(i, 20).getValue();
      var J = targetSheet.getRange(i, 23).getValue();
  
      if (dpt == p){
        if (check == true){
          var templateText = /* lots of HTML */;
          var emailText = templateText.replace("name", currentName)
            .replace("purpose", purpose)
            /* Several more replacements */
            .replace("remark", remark);
          MailApp.sendEmail({to: currentEmail, subject: "UPDATES:" + "KIT EXCHANGE REQUISITION FORM", htmlBody: emailText});
        }
      }
      else if (dpt == d){
        if (check == true){
          var templateText = /* More HTML generation */; 
          var emailText = templateText.replace("name", currentName)
            .replace("purpose", purpose)
            /* more replacements */
            .replace("remark",remark);
          MailApp.sendEmail({to: currentEmail, subject: "UPDATES:" + "KIT EXCHANGE REQUISITION FORM", htmlBody: emailText});
        }
      }
      else if (dpt == r){
        if (check == true){
          var templateText = /* HTML generation */;   
  
          var emailText = templateText.replace("name", currentName)
            .replace("purpose", purpose)
            /* More replacements */
            .replace("remark", remark);
          MailApp.sendEmail({to: currentEmail, subject: "UPDATES:" + "KIT EXCHANGE REQUISITION FORM", htmlBody: emailText});
          return(i);
        }      
      }
    }
  }
  </code></pre>