To simplify my code, I have made a function that contains an 'if' statement. The function is meant to be called within a 'For' loop in another function. I want to put a 'continue' statement inside the custom function to be called later. Is there any possible way to do this without error? Code is written in Google Apps Script.
function example1() {
//code here
continue;
}
}
function example2() {
for(var x = 1 ; x <= 2 ; x++) {
example1();
}
}
I get an error for calling the 'continue' statement within the example1() function because the 'continue' statement is not in a 'For' loop. But the example1() function is only created to be called within the example2() 'For' loop statement.
Nope, you have to directly continue inside of the for loop. You could make your function return a boolean then perform a continue as needed.
function example1() {
return shouldLoopContinue; // Add your own logic here
}
function example2() {
for (var x = 1; x <= 2; x++) {
if (example1()) {
continue;
}
doSomeOtherWork();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With