title: looping in google script
body: <p>I'm looking for help with how to run a loop in Google script for part of a function I am writing for a Google sheet (attached to a Google form). </p>
  
  <p>The purpose of this loop is to do what I suppose could be called an inverse v-lookup (i.e. the 'index' column is on the far left of the defined range instead of the far right). </p>
  
  <p>Here is my code: </p>
  
  <pre><code>//Formula to align email addresses with ticket number
  function getTicketNumber(input) {
  
  //Step 1: define spreadsheet and select sheet
    var sp = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = sp.getSheetByName("LMS-emails");
  
  //Step 2: define sheet range
  var lastRow = sheet.getLastRow();
  var lastColumn = sheet.getLastColumn();  
  var range = sheet.getRange(1,1,lastRow,lastColumn)
  var values = range.getValues();
  
  //Step 3: forumla   
    for (var i=0; i &lt;=lastRow; i++) { 
      if (values[i][3] == input) {
        return "BOOM!";}
      else {return "fizzle..."}
    }
  </code></pre>
  
  <p>}</p>
  
  <p>I've checked each step of the code leading up to the for loop and everything is working properly. If I define the row # of 'values' it will compare to my 'input' and return "BOOM!" when expected.  </p>
  
  <p>However, when I run the function with the for loop included the function returns neither "BOOM!" nor "fizzle..."; the cell is simply blank. Any thoughts on what I am doing wrong or the specificities of running a for loop in Google script much appreciated! </p>