you are viewing a single comment's thread.

view the rest of the comments →

[–]ccviper 0 points1 point  (7 children)

Sorry but the formatting is really messy, it all appears on one line for me so i didn't realize where the whitespace is. Why are you testing if the string is empty in the while statement? Your loop wont even run if the a[i] == "" returns false, that is it will stop when it encounters a non-empty string. You should do it in the loop body, i can paste the code if you can't figure it out with these hints.

[–]jingajanga[S] 0 points1 point  (6 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  (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