Skip Iteration Google Apps Script Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Skip Iteration Google Apps Script without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have a very simple For Loop in Google Apps Script to check some conditions in a Google Sheet. What I want is to add another condition, if it is met, then I want to skip current iteration and move on to next. This is pretty easy in VBA, but I am not sure how to do it on JavaScript.

Current code:

for (var i=1 ; i<=LR ; i++)
    {
     if (Val4 == "Yes")
      {
       // Skip current iteration...   <-- This is the bit I am not sure how to do
      }
     elseif (Val1 == "Accepted" && !(Val2 == "") && !(Val3 == ""))
      {
        // Do something..
       }
      else
      {
       // Do something else...
      }

    }

Answer

continue statement can be used to continue to next itteration :

for (var i=1 ; i<=LR ; i++)
{
  if (Val4 == "Yes")
  {
    continue; // Skip current iteration... 
  }
  // Do something else...
}

In your sample case, leaving the if block empty will achieve the same result:

for (var i=1; i <= LR; i++)
{
  if (Val4 == "Yes")
  {

  }
  elseif (Val1 == "Accepted" && !(Val2 == "") && !(Val3 == ""))
  {
    // Do something..
  }
  else
  {
    // Do something else...
  }
}
We are here to answer your question about Skip Iteration Google Apps Script - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji