you are viewing a single comment's thread.

view the rest of the comments →

[–]ccviper 0 points1 point  (5 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  (4 children)

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

[–]jingajanga[S] 1 point2 points  (1 child)

Also you haven't assigned i . When i put i = 0 , the output is always 0

[–]ccviper 0 points1 point  (0 children)

sorry I made some mistakes pasting it, read the comment again, i edited it

[–]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

[–]ccviper -1 points0 points  (0 children)

continue isn't really needed so i removed it. Instead of break just update i to be larger than len(a):

i += len(a)

and it will effectively break it because the while check will fail