title: set values after sending mail
body: <p><br>I want the script to send an email to those mail addresses where unchecked boxes are in the row - This works fine. But I want the value of the checkbox to be set “True” after the mails were sent.</p>
  
  <p><br> My Problem is that I need the last for-loop to stop after all checkboxes are checked. In other words: The last loop has to stop when an empty cell appears. </p>
  
  <p><br> First of all I manually trigger the script - later I will start it with the help of a button in the menu (function onOpen...) <br></p>
  
  <p><br> Appreciate any help – thanks a lot! </p>
  
  <p><br> Check out the <a href="https://docs.google.com/spreadsheets/d/1nR7Ox0bj93Rn58sldu9zYVpABjgI8u-guFQIjPpQ_pA/edit?usp=sharing" rel="nofollow noreferrer">sheet</a> and the code below:</p>
  
  <hr>
  
  <pre class="lang-default prettyprint-override"><code>
  
      function sendmail() {
  
        var ui = SpreadsheetApp.getUi();
        var ss = SpreadsheetApp.getActiveSpreadsheet();  
        var s = ss.getSheetByName('Sheet1');
        var r = s.getRange('C:C');                     //Checkboxes
        var v = r.getValues();    
         for(var i=v.length-1;i&gt;=0;i--) 
         if(v[0,i]=='false') { 
          var range = ss.getRange("A1:D4");
          var UserData = range.getValues();
          var UserData = range.getValues();
          var row = UserData[i];
          var name = row[0];
          var email = row[1];
  
          MailApp.sendEmail(row[1], "Test", "Hello " + name + ", This is an email");   
          var response = ui.alert("mail was send to ", ui.ButtonSet.OK);
  
      }
           for (k=1; k &lt; 20; k++) {               //loop which has to stop
           s.getRange(k, 3).setValue("True");
      }
      }
  
  </code></pre>