Solved

continue vs wrapping everything in an if

BellaRossiOP

Is continue better than putting the processing inside if line and not line.startswith("#"):?

7

Comments 5

Join the discussion

Already have an account? Log in

  1. SamPrice Solutionreplies: 1

    Both work. continue keeps 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.

    6
    1. BellaRossiOP

      Yeah, with three nested conditions the if version would get ugly.

      2
      1. LucasVDreplies: 1

        Strip before checking for "#" — a comment line with leading spaces otherwise slips through.

        0