Google Apps Scripts Randomly Stopping?
===

I have written a simple Google Apps script that takes details in some rows and converts them to a single list; all quite straightforward. The issue is that the script keeps stopping at random points, and the loop never finishes - there is no error message, and the message at the top of the script editor still indicates it is running, when it has clearly stopped.

I initially thought maybe it was being throttled somehow, but the random stopping points (sometimes at source sheet row 6x, sometimes at 7x, sometimes well into the hundreds) and the lack of an error message suggests otherwise.

Can anyone assist me in working out why this is happening? Is it because I am running it from the script editor window? Are there any other reasons (network issues, maybe) that an apps script could stop running, and if so, can it be run in background or similar to prevent this?

Thanks!

<pre><code>function convertTrimsToList(){
  var ss = SpreadsheetApp.openById("0AldN1zOnmW1hdHJEZkJheE0yTm1lVE4yOVQzYXpHMHc");
  var sheet = ss.getSheets()[0];
  var newss = SpreadsheetApp.create("MMT List");
  var newsheet = newss.getSheets()[0];
  
  x = 1;
  z = 1;
  i = 1;
  q = 1;
  while (sheet.getRange(x,1).getValue() != "")
  {
    sheet.getRange(1,6).setValue("Processing row " + x);
    y = 5;
    while (sheet.getRange(x,y).getValue() != "")
    {
      sheet.getRange(1,7).setValue("Processing row " + y);
      if (x != 1)
      {
         if (y == 5 && sheet.getRange(x,1).getValue() != sheet.getRange((x-1),1).getValue())
        {
          i++
        } 
      }
      newsheet.getRange(z,1).setValue(i);
      newsheet.getRange(z,2).setValue(q);
      newsheet.getRange(z,3).setValue(sheet.getRange(x,y).getValue());
      z++
      y++
    }
    if (x != 1)
      {
        if (sheet.getRange(x,3).getValue() != sheet.getRange((x-1),3).getValue())
        {
          q++
        }
      }
    else
    {
      q++
    }
    x++
  }
}</pre></code>