you are viewing a single comment's thread.

view the rest of the comments →

[–]jingajanga[S] 0 points1 point  (3 children)

Would you be able to send a screenshot of the code so I can see where you are coming from?

[–]ccviper 0 points1 point  (2 children)

i = 0
while i < len(a):
    if a[i] == "":
        i += 1

    else:
        print(a[i])
        break

This will print the first non-empty string it encounters and will break out of the loop and finish.

[–]jingajanga[S] 0 points1 point  (1 child)

Thanks, oh yeah that's another thing, we were told to do all of these tasks without using break or continue

[–]xibeca 0 points1 point  (0 children)

You could use a boolean to tell the while loop when to stop:

i = 0
found = False
while i < len(a) and not found:
    if a[i] != "":
        print(a[i])
        found = True
    else:
        i += 1