Never Ending loop, need suggestions

31 views
Skip to first unread message

Krishnendu Panja

unread,
Sep 27, 2022, 4:01:45 AM9/27/22
to Google Apps Script Community
Kindly check this script i want to put it in a never ending loop 
Please suggest.
(for(var i=0;i<50;i++) i have tried it with i<500000, it extened the loop but not to infinite

function onEdit(e)
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var mysheet = ss.getSheetByName("Sheet1");
var activeCell = ss.getActiveCell().getA1Notation();

if( activeCell == "A1" )
{
for(var i=0;i<50;i++)
{
if( i%2 == 0 )
mysheet.getRange("A1").setBackground("RED");
else
mysheet.getRange("A1").setBackground("WHITE");

SpreadsheetApp.flush();
Utilities.sleep(500);
}
}
}

Andrew Roberts

unread,
Sep 27, 2022, 4:35:43 AM9/27/22
to google-apps-sc...@googlegroups.com
A single Apps Script execution will only run for a limited time before timing out: 6 mins  for GMail accounts, 30 mins for Workspace. 

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/6ced8ff2-41a9-4c31-922d-9f3ac1415d8cn%40googlegroups.com.

Clark Lind

unread,
Sep 27, 2022, 7:18:23 AM9/27/22
to Google Apps Script Community
Wouldn't it be easier to just use Sheet Protection to protect the cell and give a warning?

CBMServices Web

unread,
Sep 27, 2022, 12:57:20 PM9/27/22
to google-apps-sc...@googlegroups.com
Or put an onEdit trigger to cause the function to run.

Infinite loops are never a good thing!


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages