If/else statements are one of the most fundamental tools in writing scripts. These
statements check to see if a statement is true, if it is true it will perform
a set of actions. If it is not true it will skip those actions and continue to the
next statement until a statement is true or it runs out of statements to check.
Example 1 - Always true
number monthNumber = month(currentDate()); string monthName = formatDate(currentDate(), "MMMM"); if(monthNumber > 0) { runnerLog("Example 1: It is the month of " + monthName + "!"); }
Example 2 - Always false
number monthNumber = month(currentDate()); string monthName = formatDate(currentDate(), "MMMM"); if(monthNumber > 12) { runnerLog("Example 2: Time no longer exists :("); }
Example 3 - Sometimes true
number monthNumber = month(currentDate()); string monthName = formatDate(currentDate(), "MMMM"); if(startsWith(monthName, "J") == true) { runnerLog("Example 3: This month " + monthName + " starts with the letter 'J'."); }
Example 4 - If, else-if
number monthNumber = month(currentDate()); string monthName = formatDate(currentDate(), "MMMM"); if(monthNumber == 1) { runnerLog("Example 4: There are 31 days this month."); } else if(monthNumber == 2) { runnerLog("Example 4: February is such a wierd month...."); }
Example 3 - If, else-if, else
number monthNumber = month(currentDate()); string monthName = formatDate(currentDate(), "MMMM"); number [] longMonths = {1,3,5,7,8,10,12}; if(arrayElementExists(longMonths, monthNumber)) { runnerLog("Example 5: There are 31 days this month."); } else if(monthNumber == 2) { runnerLog("Example 5: There are 28 or 29 days this month. Who knows..."); } else { runnerLog("Example 5: There are 30 days this month."); }