On my first acquaintance with Google Apps Script I wrote a script which picks three files on my Drive and writes the full paths to them in a text file. It seems to be working fine. getFullPathById(id) is another function I wrote which is irrelevant here.
function main() {
outputfilename = "out.txt"
content = ""
var i = 0
allfiles = DriveApp.getFiles()
while (i < 3 && allfiles.hasNext())
{
file = allfiles.next()
content += getFullPathById(file.getId())
i = i + 1
console.log(i)
}
DriveApp.createFile(outputfilename, content)
}
Though when instead of var i = 0
I simply wrote i = 0
it processed not three files but two, and logged 2 2 4
to console instead of 1 2 3
. Further when I changed i < 3
to i < 5
, it processed not 5 but twenty-something files. Where I, a newbie in Google Apps Script, can read about differences between writing var i = 0
and i = 0
?