Core LogicConditions, Loops & the for-else Trap
All courses

Branching and repeating

if/elif/else for decisions. for and while for loops. Indentation marks blocks — no curly braces required (or allowed to save you).

for n in range(1, 11):
    if n % 2 == 0:
        print(n)

Quirk #3 — for-else: Python lets you write for ... else:. The else runs only if the loop did not hit break. It confuses interviewers and delights pedants.

Goal: print each even number from 1 to 10 on its own line.

Output
Press Run to execute your code.