Unit II · Basics of Python Programming for Pharmaceutical Sciences (BP101T) · As per PCI B.Pharmacy Syllabus, NEP 2020
Loops normally run through every single iteration until their condition naturally ends, but real programs frequently need finer control than that. What if a critical patient case is found halfway through a list and there is no reason to keep checking the rest? What if one particular value in a dataset needs to be skipped while everything else is processed normally? Python answers these needs with three loop control statements — break, continue, and pass — that let a programmer alter a loop’s default behaviour from inside its own body. This post explains each one individually, contrasts them directly, and applies them to pharmacy scenarios such as scanning patient status lists.

Why Loops Need Control Statements
Loop control statements let a programmer change how a loop proceeds while it is actually running, rather than letting it simply repeat until its condition naturally ends. Instead of always running to completion, a loop might need to stop early once a certain condition is met, skip over one particular iteration while continuing with the rest, or temporarily do nothing at all while a section of code is still being written. Most programming languages, including Python, C, and Java, provide the same core pair of tools for this: break and continue. Python additionally offers a third statement, pass, which is not found as a loop-control keyword in every language and serves a rather different purpose — being a placeholder rather than actually controlling flow.
The break Statement: Exiting a Loop Early
The break statement ends a loop before it would otherwise finish. The instant the Python interpreter reaches a break inside a loop body, the loop is abandoned immediately, and execution jumps straight to the first statement that follows the loop — without running any of the remaining code in that iteration, and without running any further iterations at all.
Key Characteristics of break
- Ends the loop for good: once triggered, the loop will not run again, which is very different from merely skipping one iteration.
- Available in both loop types:
breakcan be placed inside either aforloop or awhileloop. - Typical use: applied when a specific condition has already been satisfied and continuing to loop would serve no further purpose.
for i in range(1, 6):
if i == 4:
break
print(i)
Running this prints only 1, 2, and 3. The moment i becomes 4, the break statement fires and the loop terminates immediately — before it can print 4, and before it ever gets a chance to reach 5. Now consider a pharmacy scenario where break is used to stop scanning a list of patient statuses the moment a critical case is found, so that no time is wasted checking the remaining entries:
patients = ["Normal", "Normal", "Normal", "Critical", "Normal", "Critical"]
for status in patients:
if status == "Critical":
print("Critical patient found! Stopping check.")
break
print("Patient status:", status)
The program prints the status of each normal patient in turn, and the instant it encounters the first “Critical” entry, it prints a warning message and exits the loop:
Patient status: Normal
Patient status: Normal
Patient status: Normal
Critical patient found! Stopping check.
Notice that the second “Critical” entry later in the list is never even examined, because break has already ended the loop entirely by that point. This models a genuinely useful real-world behaviour — a triage or alert system that stops as soon as it detects the first urgent case, rather than wasting processing time checking every remaining record.
The continue Statement: Skipping One Iteration
The continue statement skips whatever code remains in the current pass through the loop body and immediately moves on to the next iteration, without ending the loop itself. It is used whenever one particular iteration should be bypassed while the loop as a whole keeps running normally.
Key Characteristics of continue
- Loop keeps running:
continuedoes not stop the loop — it only affects the current cycle. - Only one iteration is affected: the remaining code for that single pass is skipped, and normal looping then resumes.
- Typical use: helpful when certain values in a sequence need to be excluded from processing while the rest are handled normally.
for i in range(1, 6):
if i == 3:
continue
print(i)
The output shows every number from 1 to 5 except 3, because the continue statement causes that single iteration to be skipped before it ever reaches print(i):
1
2
4
5
Applied to pharmaceutical data processing, continue is exactly the tool for ignoring invalid or out-of-range readings while still processing every other value in a dataset — for example, skipping a negative or clearly erroneous concentration reading in a list of assay results, without aborting the whole analysis.
The pass Statement: A Deliberate No-Operation
The pass statement performs no action at all — it is a null operation. Python’s syntax requires every loop, function, or conditional block to contain at least one statement; a block cannot simply be left empty. pass exists purely as a placeholder for situations where a block is syntactically required, but no real code needs to run there yet.
Key Characteristics of pass
- Loop behaviour is unaffected: the loop continues exactly as it would if the
passstatement were not there at all. - No effect on the program:
passdoes not change any values and does not produce any output by itself. - Typical use: commonly inserted temporarily while a program is still being written, marking a spot where code will be added later.
for i in range(1, 6):
if i == 3:
pass
print(i)
pass executes when i equals 3, but since it does nothing at all, every number from 1 to 5 is still printed normally:
1
2
3
4
5
This confirms that pass simply lets the loop continue exactly as if that line were not there at all — a sharp contrast with continue, which would have skipped the print(i) statement entirely for that iteration. A typical real use in a pharmacy application under development might look like this: a programmer drafting a drug interaction checker sketches out the branches first and fills in the logic later.
drug_class = "antibiotic"
if drug_class == "antibiotic":
pass # TODO: add interaction check for antibiotics later
elif drug_class == "analgesic":
print("Check for NSAID contraindications")
Here, pass lets the program run without errors even though the antibiotic-handling logic has not been written yet — a genuinely practical use during iterative development.
Comparing break, continue, and pass
| Statement | Purpose | Effect on Loop | Typical Pharmacy Use |
|---|---|---|---|
break |
Exit loop completely | Stops the loop entirely | Stop scanning patient records once a critical case is found |
continue |
Skip current iteration | Skips one cycle, loop keeps running | Ignore an invalid or out-of-range lab reading |
pass |
Do nothing (placeholder) | No effect at all | Mark an unfinished branch of a drug-checker for later coding |
Frequently Asked Questions
Can break and continue be used inside a while loop, not just a for loop?
Yes, both statements work identically inside while loops. break exits a while loop immediately regardless of whether its condition is still True, and continue jumps back to re-check the while loop’s condition, skipping any remaining code in that pass. This makes both statements useful for handling exceptional cases inside condition-driven loops, such as an unexpected sensor reading during a simulated dissolution test.
What happens if break is used inside a nested loop?
break only exits the innermost loop that contains it — it does not affect any outer loop. If a program is nested two loops deep (for example, looping through batches and then samples within each batch) and break is placed inside the inner sample loop, only that sample loop stops; the outer batch loop continues to its next batch as normal. To exit multiple nested loops at once, additional logic (such as a flag variable checked in the outer loop) is needed.
Is pass ever required, or is it just good practice?
pass is genuinely required whenever Python’s syntax demands a non-empty block but there is nothing to put there yet — for example, an empty function body, an empty class definition, or an if branch that intentionally does nothing. Without pass (or some other statement) in such a block, Python raises an IndentationError because it expects at least one statement inside every colon-terminated block.
Summary
Loop control statements give a Python programmer finer control over how a loop behaves than simply letting it run to completion. break exits a loop entirely and is ideal for stopping work the instant a condition — such as finding a critical patient case — makes further looping pointless. continue skips only the current iteration and lets the loop carry on, useful for excluding a specific invalid value from processing without abandoning the rest of a dataset. pass does nothing at all and exists purely to satisfy Python’s syntax when a block is required but not yet written, making it a common placeholder during active development. Recognising which of the three a given problem calls for, and correctly predicting the resulting output, is a core skill tested throughout BP101T practical assessments.
References
- Pharmacy Council of India (PCI), B.Pharm Regulations, NEP 2020 — BP101T: Basics of Python Programming for Pharmaceutical Sciences Syllabus
- Python Software Foundation, official documentation — “break and continue Statements”, The Python Tutorial
- Python Software Foundation, official documentation — “pass Statements”, The Python Tutorial
