Break & Continue in Python for Pharmacy Students (Real-Time Monitoring & Clinical Decision Interruptions)
In Python, break and continue statements are used to control loop execution. In pharmaceutical applications, they are useful in real-time patient monitoring, emergency interruptions, and selective data processing.
๐ท What are break and continue?
- break โ Stops the loop completely
- continue โ Skips current iteration and continues loop
๐ท break Statement
Used to terminate the loop immediately when a condition is met.
for i in range(5):
if i == 3:
break
print(i)
Loop stops when i becomes 3.
๐ Emergency Monitoring Stop
heart_rate = [80, 85, 90, 120, 88]
for rate in heart_rate:
if rate > 110:
print("Emergency! Stop monitoring and alert doctor")
break
print("Normal rate:", rate)
This simulates stopping monitoring when abnormal condition is detected.
๐ท continue Statement
Used to skip a specific iteration and continue with the next one.
for i in range(5):
if i == 2:
continue
print(i)
Number 2 is skipped.
๐ Skipping Invalid Data
doses = [500, -1, 650, 400]
for dose in doses:
if dose < 0:
continue
print("Valid dose:", dose)
This ignores invalid or erroneous data entries.
๐ Combined Scenario
levels = [5, 8, -1, 12, 15]
for level in levels:
if level < 0:
continue
if level > 10:
print("Toxic level detected โ stop process")
break
print("Safe level:", level)
This combines both skipping invalid data and stopping on toxicity.
๐ง Memory Trick
- break โ STOP immediately
- continue โ SKIP current
- Think: Emergency vs Ignore
๐งช Practice Exercise
Create a program that:
- Monitors patient temperature
- Stops if temperature > 104 (break)
- Skips invalid readings (continue)
๐ MCQs
- break statement:
a) Skips loop
b) Stops loop
c) Repeats loop
d) Starts loop
Answer: b - continue statement:
a) Stops loop
b) Skips iteration
c) Ends program
d) Declares variable
Answer: b - Which is used in emergency condition?
a) continue
b) break
c) print
d) input
Answer: b
โ FAQs
Why use break in pharmacy applications?
To stop processes immediately during critical conditions like toxicity or emergency.
Why use continue?
To skip invalid or irrelevant data during analysis.
๐ฅ Download Monitoring-Based Practice Exercises
Includes real-time patient monitoring simulations.
โก Next Topic: Functions in Python โ
Unit 2 Blog:
- Conditional Statements (if, if-else, if-elif)
- Nested Conditions (clinical decision logic)
- Loops (for, while) โ repetition in pharma data
- Break & Continue (control flow) (You are on this page)
- Functions (definition, arguments, return values)
- Modular Programming (Dose + BMI calculator)
Question Bank Unit 2: Control Structures & Functions
For more details: Basics of Python Programming for Pharmaceutical Sciences