3.3.2 Skipping Iterations with continue

Unit: Unit 3: Loops • Interactive Practice

Quick Answer & Summary:

Interactive Python programming tutorial and practice in your browser.

Interactive Challenge (Run Live in Browser):

# Process only valid, non-negative transactions
transactions = [100, -25, 250, 0, -50, 400]
processed_total = 0

for tx in transactions:
    if tx <= 0:
        print("Skipping non-positive transaction:", tx)
        continue  # Skip remainder of this iteration, proceed directly to next item
    
    print("Processing credit transaction:", tx)
    processed_total += tx

print("Total processed revenue:", processed_total)
Open in Live Interactive Python Sandbox →