Solved
continue vs wrapping everything in an if
Is continue better than putting the processing inside if line and not line.startswith("#"):?
Is continue better than putting the processing inside if line and not line.startswith("#"):?
Comments 5
Join the discussion CommentAlready have an account? Log in
Both work.
continuekeeps the main logic at one indentation level and puts all the "skip this" rules at the top of the loop. When stage 2 adds another skip rule (damaged lines), you'll see why it scales better.Yeah, with three nested conditions the if version would get ugly.
Same idea as guard clauses in functions, just inside a loop.
Strip before checking for "#" — a comment line with leading spaces otherwise slips through.
That was my bug! The indented comment line. Thanks.