Unit: Unit 3: Loops • Interactive Practice
Interactive Python programming tutorial and practice in your browser.
# Simulate processing user commands using a sentinel flag
is_running = True
command_queue = ["status", "sync", "exit", "reboot"]
index = 0
while is_running:
current_cmd = command_queue[index]
print("Processing command:", current_cmd)
if current_cmd == "exit":
print("Sentinel value 'exit' detected. Powering down...")
is_running = False # Toggle the state flag to cleanly stop the loop
index += 1
print("System halted successfully.")