Skip to content
Programs · Program 6-12

Q.Program 6-12: Program to demonstrate use of break statement.

Odisha ChseTextbookSubjective· 2mImportance★★★★★est
41% · 16/39 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

The break statement abandons a loop the instant it executes: this demo prints 1–5, hits break at 6, and jumps straight to the code after the loop — 7 to 10 are never processed.

The idea. Sometimes a loop should not run to completion — e.g. once a search finds its target, continuing is wasted work. break gives the loop an early exit: execution leaves the loop immediately and resumes at the first statement after the loop body.

# Program 6-12: demonstrate the use of the break statement
for num in range(1, 11):
    if num == 6:
        print("Found 6 — leaving the loop")
        break
    print(num)
print("Outside the loop")

Expected output

1
2
3
4
5
Found 6 — leaving the loop
Outside the loop

How it works

  • For num = 1…5 the if condition is False, so each number is printed.
  • When num becomes 6 the condition is True: the message prints and break executes. The loop terminates at once — the trailing print(num) of that pass and the whole remainder of the range (7, 8, 9, 10) are skipped. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.