for l in lines:
    if l.startswith('example'):
        body
for l in lines:
    if not l.startswith('example'):
        continue
body
for l in (l for l in lines if l.startswith('example')):
    body()

def gen(lines):
    return (l for l in lines if l.startswith('example'))
for line in gen(lines):
    body
for line in [l for l in lines if l.startswith('example')]:
    body()
Compound conditions in a for loop