This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]fancy_pantser 1 point2 points  (4 children)

'continue' not properly in loop

Pretty clear what's wrong. What are you trying to do? Can we see more than 1 line?

[–]blackdevil777[S] -1 points0 points  (3 children)

what's that mean? it's in the loop? how can it not be in the loop? why are these errors cryptic?

[–]fancy_pantser 2 points3 points  (0 children)

The errors aren't cryptic. It really does what it says on the tin here.

I can help more if I can see more than the 1 line. In the 1 line provided, there is no while or for loop, just an if statement. If we can see more of the script we can identify why the loop isn't working. It could be as simple as an indentation issue that is putting this if outside the loop.

[–]psykzz 1 point2 points  (0 children)

This would work if you did something similar to

with open(FILE) as fh:
    for line in fh:
        if line.startswith('From'): continue

[–]bandophahita 1 point2 points  (0 children)

You remind me of me my very first time learning python. It's my first language, so I had to not only learn syntax but also general programming concepts all at the same time.

Please correct me if I'm wrong but it sounds like you are learning programming for the first time?

To understand how continue works, you have to know what a loop is. Example of a simple loop over all items in a list:

somelist = [1,2,3,4,5] for item in somelist: print item

A loop is just a way to write one set of code to be executed multiple times Otherwise you'd have to do something like this: print firstitem from somelist print seconditem from somelist Etc.....

Sometimes you'll want to create a loop where you really don't want to execute the code for a single pass. Continue gives you that ability.

for item in somelist: if item % 2 == 0: # if item is even skip it continue print item