Script Scraper

Pull Data from the Internet into Excel Spreadsheets.

Iteration - Repetition

When a series of steps needs to be repeated a known number of times a for loop can be used.
for (var counter = 1; counter <= 5; counter++) {
        out.println("Counter is " + counter);

This example prints out the counter value five times.

>>Counter is 1
>>Counter is 2
>>Counter is 3
>>Counter is 4
>>Counter is 5

For Loops

For loops can be used to iterate over composite data structures like arrays and hashtables

var names = ['Adam', 'Bill', 'Chad', 'David'];
for each (var name in names) {  
        out.println("Name is " + name);
The output.
>>Name is Adam
>>Name is Bill
>>Name is Chad
>>Name is David
And for hashtables.
var states = ({'NY': 'New York', 
               'TX': 'Texas', 
               'CA': 'California', 
               'IL': 'Illinois'});
for each (var statename in states) {    
        out.println("name " + statename);

While Loops

These types of are useful whenever we don't know up front how many times we need to iterate.
while ("no" != hasAnotherProcessStep()) {       
        out.println("Got another one");
In the code above the functions return value determines how many iterations are executed.