🔀 Transfer / Jump Statements

Last Updated: 15 Aug 2025


Jump (or Transfer) statements are used to change the normal flow of loops or conditional execution. They either skip, stop, or do nothing.

Hinglish Tip 🗣: "Jump statements ko kuch aise smjh shkte hai ki ye program ka shortcut ya exit gate — kabhi beech mein se nikal jao, kabhi agle step pe jump kar jao."


🏷 Types of Jump Statements in Python

1. break Statement

  • Immediately terminates the loop.
  • Control moves outside the loop.
for i in range(1, 6):
    if i == 3:
        break
    print(i)
# Output:
# 1
# 2
# 👉 Loop ends as soon as i == 3.

2. continue Statement

  • Skips the current iteration of the loop.
  • Moves to the next iteration without executing remaining code inside loop.
for i in range(1, 6):
    if i == 3:
        continue
    print(i)
# Output:
# 1
# 2
# 4
# 5
#  👉 i==3 Skipped

3. pass Statement

  • Does nothing.
  • Used as a placeholder for future code.
for i in range(1, 3):
    if i == 2:
        pass
    print(i)
# Output:
# 1
# 2
# 3
# 👉 At i == 2, pass executes but does nothing.

4. else Clause with Loops

  • Python allows an else block with loops.
  • else runs only if loop finishes normally (without break).
  • If a break is used, then else won’t execute.
for i in range(1, 5):
    if i == 3:
        break
    print(i)
else:
    print("Loop finished successfully")

# Output:
# 1
# 2
# 👉 else skipped because loop ended with break

for i in range(1, 5):
    print(i)
else:
    print("Loop finished successfully")

# Output:
# 1
# 2
# 3
# 4
# Loop finished successfully
# 👉 Here else runs because loop finished without break.

Quick Summary:

StatementPurposeEffect
breakExit the loop immediatelyLoop stops; else (if any) is skipped
continueSkip current iterationMoves to next loop cycle
passDo nothing (placeholder)No action; keeps syntax valid
loop + elseRun extra block if loop ends normallyRuns only when no break occurs

💡 Quick Practice

  1. Exercises