liveBook · Manning

Continue statement

As explained in A Pythonic Adventure: From Python basics to a working web app

A continue statement skips the remaining statements in the current loop iteration and starts the next iteration.

When a customer cancels an order, the program should skip the remaining steps and return to the main menu for the next customer. The continue statement does exactly that: it skips the rest of the current loop iteration and starts the next one. section 6.0

A canceled coffee order

Inside a while True loop, a confirmed order is saved. Otherwise, continue jumps back to the beginning of the loop, showing the next customer the menu without saving the canceled order. section 6.0

Listing 6.1 A main menu with simple functions
def main_menu():
    while True:
        order = get_order()
        print("Check your order:")
        print_order(order)
        confirm = input("Confirm? Press Y to confirm, N to cancel: ")
        if confirm == "Y" or confirm == "y":
            save_order(order)
            print("Thanks for your order:")
            print_order(order)
        else:
            continue
 
 
def get_order():
    return {}
 
 
def print_order(order):
    print(order)
    return
 
 
def save_order(order):
    print("Saving order...")
    return
 
main_menu()

Browse the complete main-menu example, including the confirmation condition and continue statement. section 6.0

How A Pythonic Adventure: From Python basics to a working web app covers it

How deep it goes
Defines the iteration jump and demonstrates it inside a conditional, without exploring broader loop-control details.
Examples
Uses a coffee-shop main menu where customers confirm or cancel orders.
What it assumes
Assumes basic loops and conditional choices while building the menu structure incrementally.
What you can do after
Apply continue in Python to skip canceled work and begin the next loop iteration.
How it connects
Connects continue with loops, conditional statements, functions, and menu-driven programs.

Also explained in

Compare how 5 books explain continue statement →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of A Pythonic Adventure: From Python basics to a working web app. The section links point to the parts of the book it draws on.