Posts

Showing posts from March, 2018

Google Apps Script Loops

Loops can execute a block of code a number of times. Loops are handy, If in Google Apps Script you want to run the same code over and over again, use loops. Often this is the case when working with arrays and Google Sheet: Different Kinds of Loops Google Apps Script supports different kinds of loops: for - loops through a block of code a number of times. for/in - loops through the properties of an object. while - loops through a block of code while a specified condition is true. do/while - also loops through a block of code while a specified condition is true. For Loop The for loop is often the tool you will use when you want to create a loop. Syntax for ( statement 1 ; statement 2 ; statement 3 ) {     code block to be executed } Note: Statement 1 is executed before the loop (the code block) starts. Statement 2 defines the condition for running the loop (the code block). Statement 3 is executed each time after the loop (the code bloc

Google Apps Script Conditional Statements

Conditional statements are used to perform different actions based on different conditions. Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this. Google Apps Script will have the following conditional statements: Use if to specify a block of code to be executed, if a specified condition is true Use else to specify a block of code to be executed, if the same condition is false Use else if to specify a new condition to test, if the first condition is false Use switch to specify many alternative blocks of code to be executed if Statement Use the if statement to specify a block of Google Apps Script code to be executed if a condition is true . Syntax if ( condition ) { block of code to be executed if the condition is true; } Example “Check voting age in India” function ifCond() {  try{    var age=18;    if (age >= 18) {