Question: Using Google Apps Script, is there a more efficient way to traverse my Gmail - picking out 'non-starred' emails that have a particular label assigned to them and then download the attachments to Google Drive?

My code works, but typically 'times out' after processing about 25 image attachments (using non-paid Gmail account)

The piece of code that does the work is as follows:

```
    // Loop through the messages for each thread
    for (var i = 0 ; i < messages.length; i++) {
      for (var j = 0; j < messages[i].length; j++) {
        var CurrentMsg = messages[i][j];

          if (!CurrentMsg.isStarred()){
            var att  = CurrentMsg.getAttachments();
            // If there were no attachments, create a 'dummy text file' to notify the user that there were no attachments for that email.
            var MsgSubject = CurrentMsg.getSubject();
            if (att.length == 0){
              var file = folder.createFile(MsgSubject,'There were no attachments',MimeType.PLAIN_TEXT);
            }
            else{  
              for (var k = 0; k < att.length; k++){
                var file = folder.createFile(att[k].copyBlob().getAs('image/jpeg').setName(MsgSubject));
              }
             }
            CurrentMsg.star();
          }
      }
    }  

```

Any tips gratefully received!

Answer: 
Update: because you say *`(How should I revise this code by not using list comprehension or other methods?)`* I send this answer otherwise other answers are better for the future.

You need to increase the index, here in your code `x+=1` like below:

```
list1 = ["apple", "pear", "", "strawberry", "orange", "grapes", "", "watermelon"]
list2 = []
x = 0
while x < len(list1):
    if len(list1[x]) > 0:
        list2.append(list1[x])
    x += 1
print(list2)

```

Output:

```none
['apple', 'pear', 'strawberry', 'orange', 'grapes', 'watermelon']

```
Assuming that this is your desired output:

```
['apple', 'pear', 'strawberry', 'orange', 'grapes', 'watermelon']

```

Here's a way without using builtins or list comprehensions:

```py
list1 = ["apple", "pear", "", "strawberry", "orange", "grapes", "", "watermelon"]

list2 = []
for x in list1:
    x and list2.append(x)

```

Assuming are allowed to use builtins such as `filter`:

```py
list1 = ["apple", "pear", "", "strawberry", "orange", "grapes", "", "watermelon"]
list2 = list(filter(None, list1))

```